blob: b367cff7c8a13bd22c86243e7302b5e30664a40a [file] [log] [blame]
Ian Rogersb0fa5dc2014-04-28 16:47:08 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_MIRROR_STRING_INL_H_
18#define ART_RUNTIME_MIRROR_STRING_INL_H_
19
20#include "array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070021#include "class.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070022#include "intern_table.h"
23#include "runtime.h"
24#include "string.h"
25#include "thread.h"
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -070026#include "utf.h"
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070027
28namespace art {
29namespace mirror {
30
Mingyao Yang98d1cc82014-05-15 17:02:16 -070031inline uint32_t String::ClassSize() {
32 uint32_t vtable_entries = Object::kVTableLength + 51;
Fred Shih37f05ef2014-07-16 18:38:08 -070033 return Class::ComputeClassSize(true, vtable_entries, 0, 1, 0, 1, 2);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070034}
35
Narayan Kamatha5afcfc2015-01-29 20:06:46 +000036inline uint16_t String::UncheckedCharAt(int32_t index) {
37 return GetCharArray()->Get(index + GetOffset());
38}
39
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070040inline CharArray* String::GetCharArray() {
41 return GetFieldObject<CharArray>(ValueOffset());
42}
43
44inline int32_t String::GetLength() {
45 int32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(String, count_));
46 DCHECK(result >= 0 && result <= GetCharArray()->GetLength());
47 return result;
48}
49
50inline void String::SetArray(CharArray* new_array) {
51 // Array is invariant so use non-transactional mode. Also disable check as we may run inside
52 // a transaction.
Mathieu Chartier2cebb242015-04-21 16:50:40 -070053 DCHECK(new_array != nullptr);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070054 SetFieldObject<false, false>(OFFSET_OF_OBJECT_MEMBER(String, array_), new_array);
55}
56
57inline String* String::Intern() {
58 return Runtime::Current()->GetInternTable()->InternWeak(this);
59}
60
Mathieu Chartiercdfd39f2014-08-29 18:16:58 -070061inline int32_t String::GetHashCode() {
62 int32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(String, hash_code_));
63 if (UNLIKELY(result == 0)) {
64 result = ComputeHashCode();
65 }
66 DCHECK(result != 0 || ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength()) == 0)
67 << ToModifiedUtf8() << " " << result;
68 return result;
69}
70
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070071} // namespace mirror
72} // namespace art
73
74#endif // ART_RUNTIME_MIRROR_STRING_INL_H_