Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 3 | #include "object.h" |
| 4 | |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 5 | #include <string.h> |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 6 | |
Ian Rogers | df20fe0 | 2011-07-20 20:34:16 -0700 | [diff] [blame] | 7 | #include <algorithm> |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <utility> |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 10 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 11 | #include "class_linker.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 12 | #include "class_loader.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 13 | #include "globals.h" |
Brian Carlstrom | a40f9bc | 2011-07-26 21:26:07 -0700 | [diff] [blame] | 14 | #include "heap.h" |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 15 | #include "intern_table.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 16 | #include "logging.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 17 | #include "dex_cache.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 18 | #include "dex_file.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 19 | #include "runtime.h" |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 20 | |
| 21 | namespace art { |
| 22 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 23 | bool Object::IsString() const { |
| 24 | // TODO use "klass_ == String::GetJavaLangString()" instead? |
| 25 | return GetClass() == GetClass()->GetDescriptor()->GetClass(); |
| 26 | } |
| 27 | |
| 28 | // TODO: get global references for these |
| 29 | Class* Field::java_lang_reflect_Field_ = NULL; |
| 30 | |
| 31 | void Field::SetClass(Class* java_lang_reflect_Field) { |
| 32 | CHECK(java_lang_reflect_Field_ == NULL); |
| 33 | CHECK(java_lang_reflect_Field != NULL); |
| 34 | java_lang_reflect_Field_ = java_lang_reflect_Field; |
| 35 | } |
| 36 | |
| 37 | void Field::ResetClass() { |
| 38 | CHECK(java_lang_reflect_Field_ != NULL); |
| 39 | java_lang_reflect_Field_ = NULL; |
| 40 | } |
| 41 | |
| 42 | void Field::SetTypeIdx(uint32_t type_idx) { |
| 43 | SetField32(OFFSET_OF_OBJECT_MEMBER(Field, type_idx_), type_idx, false); |
| 44 | } |
| 45 | |
| 46 | Class* Field::GetTypeDuringLinking() const { |
| 47 | // We are assured that the necessary primitive types are in the dex cache |
| 48 | // early during class linking |
| 49 | return GetDeclaringClass()->GetDexCache()->GetResolvedType(GetTypeIdx()); |
| 50 | } |
| 51 | |
| 52 | Class* Field::GetType() const { |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 53 | DCHECK(Runtime::Current()->IsStarted()) |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 54 | << "Can't call GetType without an initialized runtime"; |
| 55 | // Do full linkage (which sets dex cache value to speed next call) |
| 56 | return Runtime::Current()->GetClassLinker()->ResolveType(GetTypeIdx(), this); |
| 57 | } |
| 58 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 59 | Field* FindFieldFromCode(uint32_t field_idx, const Method* referrer) { |
| 60 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 61 | Field* f = class_linker->ResolveField(field_idx, referrer); |
| 62 | if (f != NULL) { |
| 63 | Class* c = f->GetDeclaringClass(); |
| 64 | // If the class is already initializing, we must be inside <clinit>, or |
| 65 | // we'd still be waiting for the lock. |
| 66 | if (c->GetStatus() == Class::kStatusInitializing || class_linker->EnsureInitialized(c)) { |
| 67 | return f; |
| 68 | } |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 69 | } |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 70 | UNIMPLEMENTED(FATAL) << "throw an error and unwind"; |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | uint32_t Field::Get32StaticFromCode(uint32_t field_idx, const Method* referrer) { |
| 75 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 76 | DCHECK(field->GetType()->PrimitiveSize() == sizeof(int32_t)); |
| 77 | return field->Get32(NULL); |
| 78 | } |
| 79 | void Field::Set32StaticFromCode(uint32_t field_idx, const Method* referrer, uint32_t new_value) { |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 80 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 81 | DCHECK(field->GetType()->PrimitiveSize() == sizeof(int32_t)); |
| 82 | field->Set32(NULL, new_value); |
| 83 | } |
| 84 | uint64_t Field::Get64StaticFromCode(uint32_t field_idx, const Method* referrer) { |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 85 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 86 | DCHECK(field->GetType()->PrimitiveSize() == sizeof(int64_t)); |
| 87 | return field->Get64(NULL); |
| 88 | } |
| 89 | void Field::Set64StaticFromCode(uint32_t field_idx, const Method* referrer, uint64_t new_value) { |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 90 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 91 | DCHECK(field->GetType()->PrimitiveSize() == sizeof(int64_t)); |
| 92 | field->Set64(NULL, new_value); |
| 93 | } |
| 94 | Object* Field::GetObjStaticFromCode(uint32_t field_idx, const Method* referrer) { |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 95 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 96 | DCHECK(!field->GetType()->IsPrimitive()); |
| 97 | return field->GetObj(NULL); |
| 98 | } |
| 99 | void Field::SetObjStaticFromCode(uint32_t field_idx, const Method* referrer, Object* new_value) { |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 100 | Field* field = FindFieldFromCode(field_idx, referrer); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 101 | DCHECK(!field->GetType()->IsPrimitive()); |
| 102 | field->SetObj(NULL, new_value); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 105 | uint32_t Field::Get32(const Object* object) const { |
| 106 | CHECK((object == NULL) == IsStatic()); |
| 107 | if (IsStatic()) { |
| 108 | object = declaring_class_; |
| 109 | } |
| 110 | return object->GetField32(GetOffset(), IsVolatile()); |
Elliott Hughes | 68f4fa0 | 2011-08-21 10:46:59 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 113 | void Field::Set32(Object* object, uint32_t new_value) const { |
| 114 | CHECK((object == NULL) == IsStatic()); |
| 115 | if (IsStatic()) { |
| 116 | object = declaring_class_; |
| 117 | } |
| 118 | object->SetField32(GetOffset(), new_value, IsVolatile()); |
| 119 | } |
| 120 | |
| 121 | uint64_t Field::Get64(const Object* object) const { |
| 122 | CHECK((object == NULL) == IsStatic()); |
| 123 | if (IsStatic()) { |
| 124 | object = declaring_class_; |
| 125 | } |
| 126 | return object->GetField64(GetOffset(), IsVolatile()); |
| 127 | } |
| 128 | |
| 129 | void Field::Set64(Object* object, uint64_t new_value) const { |
| 130 | CHECK((object == NULL) == IsStatic()); |
| 131 | if (IsStatic()) { |
| 132 | object = declaring_class_; |
| 133 | } |
| 134 | object->SetField64(GetOffset(), new_value, IsVolatile()); |
| 135 | } |
| 136 | |
| 137 | Object* Field::GetObj(const Object* object) const { |
| 138 | CHECK((object == NULL) == IsStatic()); |
| 139 | if (IsStatic()) { |
| 140 | object = declaring_class_; |
| 141 | } |
| 142 | return object->GetFieldObject<Object*>(GetOffset(), IsVolatile()); |
| 143 | } |
| 144 | |
| 145 | void Field::SetObj(Object* object, const Object* new_value) const { |
| 146 | CHECK((object == NULL) == IsStatic()); |
| 147 | if (IsStatic()) { |
| 148 | object = declaring_class_; |
| 149 | } |
| 150 | object->SetFieldObject(GetOffset(), new_value, IsVolatile()); |
| 151 | } |
| 152 | |
| 153 | bool Field::GetBoolean(const Object* object) const { |
| 154 | DCHECK(GetType()->IsPrimitiveBoolean()); |
| 155 | return Get32(object); |
| 156 | } |
| 157 | |
| 158 | void Field::SetBoolean(Object* object, bool z) const { |
| 159 | DCHECK(GetType()->IsPrimitiveBoolean()); |
| 160 | Set32(object, z); |
| 161 | } |
| 162 | |
| 163 | int8_t Field::GetByte(const Object* object) const { |
| 164 | DCHECK(GetType()->IsPrimitiveByte()); |
| 165 | return Get32(object); |
| 166 | } |
| 167 | |
| 168 | void Field::SetByte(Object* object, int8_t b) const { |
| 169 | DCHECK(GetType()->IsPrimitiveByte()); |
| 170 | Set32(object, b); |
| 171 | } |
| 172 | |
| 173 | uint16_t Field::GetChar(const Object* object) const { |
| 174 | DCHECK(GetType()->IsPrimitiveChar()); |
| 175 | return Get32(object); |
| 176 | } |
| 177 | |
| 178 | void Field::SetChar(Object* object, uint16_t c) const { |
| 179 | DCHECK(GetType()->IsPrimitiveChar()); |
| 180 | Set32(object, c); |
| 181 | } |
| 182 | |
| 183 | uint16_t Field::GetShort(const Object* object) const { |
| 184 | DCHECK(GetType()->IsPrimitiveShort()); |
| 185 | return Get32(object); |
| 186 | } |
| 187 | |
| 188 | void Field::SetShort(Object* object, uint16_t s) const { |
| 189 | DCHECK(GetType()->IsPrimitiveShort()); |
| 190 | Set32(object, s); |
| 191 | } |
| 192 | |
| 193 | int32_t Field::GetInt(const Object* object) const { |
| 194 | DCHECK(GetType()->IsPrimitiveInt()); |
| 195 | return Get32(object); |
| 196 | } |
| 197 | |
| 198 | void Field::SetInt(Object* object, int32_t i) const { |
| 199 | DCHECK(GetType()->IsPrimitiveInt()); |
| 200 | Set32(object, i); |
| 201 | } |
| 202 | |
| 203 | int64_t Field::GetLong(const Object* object) const { |
| 204 | DCHECK(GetType()->IsPrimitiveLong()); |
| 205 | return Get64(object); |
| 206 | } |
| 207 | |
| 208 | void Field::SetLong(Object* object, int64_t j) const { |
| 209 | DCHECK(GetType()->IsPrimitiveLong()); |
| 210 | Set64(object, j); |
| 211 | } |
| 212 | |
| 213 | float Field::GetFloat(const Object* object) const { |
| 214 | DCHECK(GetType()->IsPrimitiveFloat()); |
| 215 | JValue float_bits; |
| 216 | float_bits.i = Get32(object); |
| 217 | return float_bits.f; |
| 218 | } |
| 219 | |
| 220 | void Field::SetFloat(Object* object, float f) const { |
| 221 | DCHECK(GetType()->IsPrimitiveFloat()); |
| 222 | JValue float_bits; |
| 223 | float_bits.f = f; |
| 224 | Set32(object, float_bits.i); |
| 225 | } |
| 226 | |
| 227 | double Field::GetDouble(const Object* object) const { |
| 228 | DCHECK(GetType()->IsPrimitiveDouble()); |
| 229 | JValue double_bits; |
| 230 | double_bits.j = Get64(object); |
| 231 | return double_bits.d; |
| 232 | } |
| 233 | |
| 234 | void Field::SetDouble(Object* object, double d) const { |
| 235 | DCHECK(GetType()->IsPrimitiveDouble()); |
| 236 | JValue double_bits; |
| 237 | double_bits.d = d; |
| 238 | Set64(object, double_bits.j); |
| 239 | } |
| 240 | |
| 241 | Object* Field::GetObject(const Object* object) const { |
| 242 | CHECK(!GetType()->IsPrimitive()); |
| 243 | return GetObj(object); |
| 244 | } |
| 245 | |
| 246 | void Field::SetObject(Object* object, const Object* l) const { |
| 247 | CHECK(!GetType()->IsPrimitive()); |
| 248 | SetObj(object, l); |
| 249 | } |
| 250 | |
| 251 | // TODO: get global references for these |
| 252 | Class* Method::java_lang_reflect_Method_ = NULL; |
| 253 | |
| 254 | void Method::SetClass(Class* java_lang_reflect_Method) { |
| 255 | CHECK(java_lang_reflect_Method_ == NULL); |
| 256 | CHECK(java_lang_reflect_Method != NULL); |
| 257 | java_lang_reflect_Method_ = java_lang_reflect_Method; |
| 258 | } |
| 259 | |
| 260 | void Method::ResetClass() { |
| 261 | CHECK(java_lang_reflect_Method_ != NULL); |
| 262 | java_lang_reflect_Method_ = NULL; |
| 263 | } |
| 264 | |
| 265 | ObjectArray<String>* Method::GetDexCacheStrings() const { |
| 266 | return GetFieldObject<ObjectArray<String>*>( |
| 267 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_strings_), false); |
| 268 | } |
| 269 | |
| 270 | void Method::SetReturnTypeIdx(uint32_t new_return_type_idx) { |
| 271 | SetField32(OFFSET_OF_OBJECT_MEMBER(Method, java_return_type_idx_), |
| 272 | new_return_type_idx, false); |
| 273 | } |
| 274 | |
| 275 | Class* Method::GetReturnType() const { |
| 276 | DCHECK(GetDeclaringClass()->IsLinked()); |
| 277 | // Short-cut |
| 278 | Class* result = GetDexCacheResolvedTypes()->Get(GetReturnTypeIdx()); |
| 279 | if (result == NULL) { |
| 280 | // Do full linkage and set cache value for next call |
| 281 | result = Runtime::Current()->GetClassLinker()->ResolveType(GetReturnTypeIdx(), this); |
| 282 | } |
| 283 | CHECK(result != NULL); |
| 284 | return result; |
| 285 | } |
| 286 | |
| 287 | void Method::SetDexCacheStrings(ObjectArray<String>* new_dex_cache_strings) { |
| 288 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_strings_), |
| 289 | new_dex_cache_strings, false); |
| 290 | } |
| 291 | |
| 292 | ObjectArray<Class>* Method::GetDexCacheResolvedTypes() const { |
| 293 | return GetFieldObject<ObjectArray<Class>*>( |
| 294 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_types_), false); |
| 295 | } |
| 296 | |
| 297 | void Method::SetDexCacheResolvedTypes(ObjectArray<Class>* new_dex_cache_classes) { |
| 298 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_types_), |
| 299 | new_dex_cache_classes, false); |
| 300 | } |
| 301 | |
| 302 | ObjectArray<Method>* Method::GetDexCacheResolvedMethods() const { |
| 303 | return GetFieldObject<ObjectArray<Method>*>( |
| 304 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_methods_), false); |
| 305 | } |
| 306 | |
| 307 | void Method::SetDexCacheResolvedMethods(ObjectArray<Method>* new_dex_cache_methods) { |
| 308 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_methods_), |
| 309 | new_dex_cache_methods, false); |
| 310 | } |
| 311 | |
| 312 | ObjectArray<Field>* Method::GetDexCacheResolvedFields() const { |
| 313 | return GetFieldObject<ObjectArray<Field>*>( |
| 314 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_fields_), false); |
| 315 | } |
| 316 | |
| 317 | void Method::SetDexCacheResolvedFields(ObjectArray<Field>* new_dex_cache_fields) { |
| 318 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_resolved_fields_), |
| 319 | new_dex_cache_fields, false); |
| 320 | } |
| 321 | |
| 322 | CodeAndDirectMethods* Method::GetDexCacheCodeAndDirectMethods() const { |
| 323 | return GetFieldPtr<CodeAndDirectMethods*>( |
| 324 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_code_and_direct_methods_), |
| 325 | false); |
| 326 | } |
| 327 | |
| 328 | void Method::SetDexCacheCodeAndDirectMethods(CodeAndDirectMethods* new_value) { |
| 329 | SetFieldPtr<CodeAndDirectMethods*>( |
| 330 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_code_and_direct_methods_), |
| 331 | new_value, false); |
| 332 | } |
| 333 | |
| 334 | ObjectArray<StaticStorageBase>* Method::GetDexCacheInitializedStaticStorage() const { |
| 335 | return GetFieldObject<ObjectArray<StaticStorageBase>*>( |
| 336 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_initialized_static_storage_), |
| 337 | false); |
| 338 | } |
| 339 | |
| 340 | void Method::SetDexCacheInitializedStaticStorage(ObjectArray<StaticStorageBase>* new_value) { |
| 341 | SetFieldObject( |
| 342 | OFFSET_OF_OBJECT_MEMBER(Method, dex_cache_initialized_static_storage_), |
| 343 | new_value, false); |
| 344 | |
| 345 | } |
| 346 | |
| 347 | size_t Method::NumArgRegisters(const StringPiece& shorty) { |
| 348 | CHECK_LE(1, shorty.length()); |
| 349 | uint32_t num_registers = 0; |
| 350 | for (int i = 1; i < shorty.length(); ++i) { |
| 351 | char ch = shorty[i]; |
| 352 | if (ch == 'D' || ch == 'J') { |
| 353 | num_registers += 2; |
| 354 | } else { |
| 355 | num_registers += 1; |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 358 | return num_registers; |
| 359 | } |
| 360 | |
| 361 | size_t Method::NumArgArrayBytes() const { |
| 362 | const StringPiece& shorty = GetShorty(); |
| 363 | size_t num_bytes = 0; |
| 364 | for (int i = 1; i < shorty.length(); ++i) { |
| 365 | char ch = shorty[i]; |
| 366 | if (ch == 'D' || ch == 'J') { |
| 367 | num_bytes += 8; |
| 368 | } else if (ch == 'L') { |
| 369 | // Argument is a reference or an array. The shorty descriptor |
| 370 | // does not distinguish between these types. |
| 371 | num_bytes += sizeof(Object*); |
| 372 | } else { |
| 373 | num_bytes += 4; |
| 374 | } |
| 375 | } |
| 376 | return num_bytes; |
| 377 | } |
| 378 | |
| 379 | // The number of reference arguments to this method including implicit this |
| 380 | // pointer |
| 381 | size_t Method::NumReferenceArgs() const { |
| 382 | const StringPiece& shorty = GetShorty(); |
| 383 | size_t result = IsStatic() ? 0 : 1; // The implicit this pointer. |
| 384 | for (int i = 1; i < shorty.length(); i++) { |
| 385 | if ((shorty[i] == 'L') || (shorty[i] == '[')) { |
| 386 | result++; |
| 387 | } |
| 388 | } |
| 389 | return result; |
| 390 | } |
| 391 | |
| 392 | // The number of long or double arguments |
| 393 | size_t Method::NumLongOrDoubleArgs() const { |
| 394 | const StringPiece& shorty = GetShorty(); |
| 395 | size_t result = 0; |
| 396 | for (int i = 1; i < shorty.length(); i++) { |
| 397 | if ((shorty[i] == 'D') || (shorty[i] == 'J')) { |
| 398 | result++; |
| 399 | } |
| 400 | } |
| 401 | return result; |
| 402 | } |
| 403 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 404 | // Is the given method parameter a reference? |
| 405 | bool Method::IsParamAReference(unsigned int param) const { |
| 406 | CHECK_LT(param, NumArgs()); |
| 407 | if (IsStatic()) { |
| 408 | param++; // 0th argument must skip return value at start of the shorty |
| 409 | } else if (param == 0) { |
| 410 | return true; // this argument |
| 411 | } |
| 412 | return GetShorty()[param] == 'L'; |
| 413 | } |
| 414 | |
| 415 | // Is the given method parameter a long or double? |
| 416 | bool Method::IsParamALongOrDouble(unsigned int param) const { |
| 417 | CHECK_LT(param, NumArgs()); |
| 418 | if (IsStatic()) { |
| 419 | param++; // 0th argument must skip return value at start of the shorty |
| 420 | } else if (param == 0) { |
| 421 | return false; // this argument |
| 422 | } |
| 423 | return (GetShorty()[param] == 'J') || (GetShorty()[param] == 'D'); |
| 424 | } |
| 425 | |
| 426 | static size_t ShortyCharToSize(char x) { |
| 427 | switch (x) { |
| 428 | case 'V': return 0; |
| 429 | case '[': return kPointerSize; |
| 430 | case 'L': return kPointerSize; |
| 431 | case 'D': return 8; |
| 432 | case 'J': return 8; |
| 433 | default: return 4; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | size_t Method::ParamSize(unsigned int param) const { |
| 438 | CHECK_LT(param, NumArgs()); |
| 439 | if (IsStatic()) { |
| 440 | param++; // 0th argument must skip return value at start of the shorty |
| 441 | } else if (param == 0) { |
| 442 | return kPointerSize; // this argument |
| 443 | } |
| 444 | return ShortyCharToSize(GetShorty()[param]); |
| 445 | } |
| 446 | |
| 447 | size_t Method::ReturnSize() const { |
| 448 | return ShortyCharToSize(GetShorty()[0]); |
| 449 | } |
| 450 | |
| 451 | bool Method::HasSameNameAndDescriptor(const Method* that) const { |
| 452 | return (this->GetName()->Equals(that->GetName()) && |
| 453 | this->GetSignature()->Equals(that->GetSignature())); |
| 454 | } |
| 455 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 456 | void Method::SetCode(ByteArray* code_array, |
| 457 | InstructionSet instruction_set) { |
| 458 | CHECK(!HasCode() || IsNative()); |
| 459 | SetFieldPtr<ByteArray*>(OFFSET_OF_OBJECT_MEMBER(Method, code_array_), code_array, false); |
| 460 | int8_t* code = code_array->GetData(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 461 | uintptr_t address = reinterpret_cast<uintptr_t>(code); |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 462 | if (instruction_set == kThumb2) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 463 | // Set the low-order bit so a BLX will switch to Thumb mode |
| 464 | address |= 0x1; |
| 465 | } |
| 466 | SetFieldPtr<uintptr_t>(OFFSET_OF_OBJECT_MEMBER(Method, code_), address, false); |
| 467 | } |
| 468 | |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 469 | void Method::SetInvokeStub(const ByteArray* invoke_stub_array) { |
| 470 | const InvokeStub* invoke_stub = reinterpret_cast<InvokeStub*>(invoke_stub_array->GetData()); |
| 471 | SetFieldPtr<const ByteArray*>( |
| 472 | OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_array_), invoke_stub_array, false); |
| 473 | SetFieldPtr<const InvokeStub*>( |
| 474 | OFFSET_OF_OBJECT_MEMBER(Method, invoke_stub_), invoke_stub, false); |
| 475 | } |
| 476 | |
Elliott Hughes | f5ecf06 | 2011-09-06 17:37:59 -0700 | [diff] [blame] | 477 | void Method::Invoke(Thread* self, Object* receiver, byte* args, JValue* result) const { |
| 478 | // Push a transition back into managed code onto the linked list in thread. |
| 479 | CHECK_EQ(Thread::kRunnable, self->GetState()); |
| 480 | NativeToManagedRecord record; |
| 481 | self->PushNativeToManagedRecord(&record); |
| 482 | |
| 483 | // Call the invoke stub associated with the method. |
| 484 | // Pass everything as arguments. |
| 485 | const Method::InvokeStub* stub = GetInvokeStub(); |
| 486 | if (HasCode() && stub != NULL) { |
| 487 | (*stub)(this, receiver, self, args, result); |
| 488 | } else { |
| 489 | LOG(WARNING) << "Not invoking method with no associated code: " << PrettyMethod(this); |
| 490 | if (result != NULL) { |
| 491 | result->j = 0; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | // Pop transition. |
| 496 | self->PopNativeToManagedRecord(record); |
| 497 | } |
| 498 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 499 | void Class::SetStatus(Status new_status) { |
| 500 | CHECK(new_status > GetStatus() || new_status == kStatusError || |
Elliott Hughes | dcc2474 | 2011-09-07 14:02:44 -0700 | [diff] [blame] | 501 | !Runtime::Current()->IsStarted()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 502 | CHECK(sizeof(Status) == sizeof(uint32_t)); |
| 503 | return SetField32(OFFSET_OF_OBJECT_MEMBER(Class, status_), |
| 504 | new_status, false); |
| 505 | } |
| 506 | |
| 507 | DexCache* Class::GetDexCache() const { |
| 508 | return GetFieldObject<DexCache*>( |
| 509 | OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), false); |
| 510 | } |
| 511 | |
| 512 | void Class::SetDexCache(DexCache* new_dex_cache) { |
| 513 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, dex_cache_), |
| 514 | new_dex_cache, false); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 517 | Object* Class::AllocObjectFromCode(uint32_t type_idx, Method* method) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 518 | Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 519 | if (klass == NULL) { |
| 520 | klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); |
| 521 | if (klass == NULL) { |
| 522 | UNIMPLEMENTED(FATAL) << "throw an error"; |
| 523 | return NULL; |
| 524 | } |
| 525 | } |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 526 | return klass->AllocObject(); |
| 527 | } |
| 528 | |
| 529 | Object* Class::AllocObject() { |
| 530 | DCHECK(!IsAbstract()); |
| 531 | return Heap::AllocObject(this, this->object_size_); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 534 | void Class::SetReferenceInstanceOffsets(uint32_t new_reference_offsets) { |
| 535 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 536 | // Sanity check that the number of bits set in the reference offset bitmap |
| 537 | // agrees with the number of references |
| 538 | Class* cur = this; |
| 539 | size_t cnt = 0; |
| 540 | while (cur) { |
| 541 | cnt += cur->NumReferenceInstanceFieldsDuringLinking(); |
| 542 | cur = cur->GetSuperClass(); |
| 543 | } |
| 544 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), cnt); |
| 545 | } |
| 546 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_instance_offsets_), |
| 547 | new_reference_offsets, false); |
| 548 | } |
| 549 | |
| 550 | void Class::SetReferenceStaticOffsets(uint32_t new_reference_offsets) { |
| 551 | if (new_reference_offsets != CLASS_WALK_SUPER) { |
| 552 | // Sanity check that the number of bits set in the reference offset bitmap |
| 553 | // agrees with the number of references |
| 554 | CHECK_EQ((size_t)__builtin_popcount(new_reference_offsets), |
| 555 | NumReferenceStaticFieldsDuringLinking()); |
| 556 | } |
| 557 | SetField32(OFFSET_OF_OBJECT_MEMBER(Class, reference_static_offsets_), |
| 558 | new_reference_offsets, false); |
| 559 | } |
| 560 | |
| 561 | size_t Class::PrimitiveSize() const { |
| 562 | switch (GetPrimitiveType()) { |
| 563 | case kPrimBoolean: |
| 564 | case kPrimByte: |
| 565 | case kPrimChar: |
| 566 | case kPrimShort: |
| 567 | case kPrimInt: |
| 568 | case kPrimFloat: |
| 569 | return sizeof(int32_t); |
| 570 | case kPrimLong: |
| 571 | case kPrimDouble: |
| 572 | return sizeof(int64_t); |
| 573 | default: |
| 574 | LOG(FATAL) << "Primitive type size calculation on invalid type " << this; |
| 575 | return 0; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | size_t Class::GetTypeSize(const String* descriptor) { |
| 580 | switch (descriptor->CharAt(0)) { |
| 581 | case 'B': return 1; // byte |
| 582 | case 'C': return 2; // char |
| 583 | case 'D': return 8; // double |
| 584 | case 'F': return 4; // float |
| 585 | case 'I': return 4; // int |
| 586 | case 'J': return 8; // long |
| 587 | case 'S': return 2; // short |
| 588 | case 'Z': return 1; // boolean |
| 589 | case 'L': return sizeof(Object*); |
| 590 | case '[': return sizeof(Array*); |
| 591 | default: |
| 592 | LOG(ERROR) << "Unknown type " << descriptor; |
| 593 | return 0; |
| 594 | } |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 597 | bool Class::Implements(const Class* klass) const { |
| 598 | DCHECK(klass != NULL); |
| 599 | DCHECK(klass->IsInterface()); |
| 600 | // All interfaces implemented directly and by our superclass, and |
| 601 | // recursively all super-interfaces of those interfaces, are listed |
| 602 | // in iftable_, so we can just do a linear scan through that. |
| 603 | for (size_t i = 0; i < iftable_count_; i++) { |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 604 | if (iftable_[i].GetInterface() == klass) { |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 605 | return true; |
| 606 | } |
| 607 | } |
| 608 | return false; |
| 609 | } |
| 610 | |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 611 | bool Class::CanPutArrayElement(const Class* object_class, const Class* array_class) { |
| 612 | if (object_class->IsArrayClass()) { |
| 613 | return array_class->IsArrayAssignableFromArray(object_class); |
| 614 | } else { |
| 615 | return array_class->GetComponentType()->IsAssignableFrom(object_class); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | void Class::CanPutArrayElementFromCode(const Class* object_class, const Class* array_class) { |
| 620 | if (!CanPutArrayElement(object_class, array_class)) { |
| 621 | LOG(ERROR) << "Can't put a " << PrettyDescriptor(object_class->GetDescriptor()) |
| 622 | << " into a " << PrettyDescriptor(array_class->GetDescriptor()); |
| 623 | UNIMPLEMENTED(FATAL) << "need to throw ArrayStoreException and unwind stack"; |
| 624 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 627 | // Determine whether "this" is assignable from "klazz", where both of these |
| 628 | // are array classes. |
| 629 | // |
| 630 | // Consider an array class, e.g. Y[][], where Y is a subclass of X. |
| 631 | // Y[][] = Y[][] --> true (identity) |
| 632 | // X[][] = Y[][] --> true (element superclass) |
| 633 | // Y = Y[][] --> false |
| 634 | // Y[] = Y[][] --> false |
| 635 | // Object = Y[][] --> true (everything is an object) |
| 636 | // Object[] = Y[][] --> true |
| 637 | // Object[][] = Y[][] --> true |
| 638 | // Object[][][] = Y[][] --> false (too many []s) |
| 639 | // Serializable = Y[][] --> true (all arrays are Serializable) |
| 640 | // Serializable[] = Y[][] --> true |
| 641 | // Serializable[][] = Y[][] --> false (unless Y is Serializable) |
| 642 | // |
| 643 | // Don't forget about primitive types. |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 644 | // Object[] = int[] --> false |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 645 | // |
| 646 | bool Class::IsArrayAssignableFromArray(const Class* klass) const { |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 647 | DCHECK(IsArrayClass()); |
| 648 | DCHECK(klass->IsArrayClass()); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 649 | DCHECK_GT(GetArrayRank(), 0); |
| 650 | DCHECK_GT(klass->GetArrayRank(), 0); |
| 651 | DCHECK(GetComponentType() != NULL); |
| 652 | DCHECK(klass->GetComponentType() != NULL); |
| 653 | if (GetArrayRank() > klass->GetArrayRank()) { |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 654 | // Too many []s. |
| 655 | return false; |
| 656 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 657 | if (GetArrayRank() == klass->GetArrayRank()) { |
| 658 | return GetComponentType()->IsAssignableFrom(klass->GetComponentType()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 659 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 660 | DCHECK_LT(GetArrayRank(), klass->GetArrayRank()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 661 | // The thing we might be assignable from has more dimensions. We |
| 662 | // must be an Object or array of Object, or a standard array |
| 663 | // interface or array of standard array interfaces (the standard |
| 664 | // interfaces being java/lang/Cloneable and java/io/Serializable). |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 665 | if (GetComponentType()->IsInterface()) { |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 666 | // See if we implement our component type. We know the |
| 667 | // base element is an interface; if the array class implements |
| 668 | // it, we know it's a standard array interface. |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 669 | return Implements(GetComponentType()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 670 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 671 | // See if this is an array of Object, Object[], etc. |
| 672 | return GetComponentType()->IsObjectClass(); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | bool Class::IsAssignableFromArray(const Class* klass) const { |
| 676 | DCHECK(!IsInterface()); // handled first in IsAssignableFrom |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 677 | DCHECK(klass->IsArrayClass()); |
| 678 | if (!IsArrayClass()) { |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 679 | // If "this" is not also an array, it must be Object. |
| 680 | // klass's super should be java_lang_Object, since it is an array. |
| 681 | Class* java_lang_Object = klass->GetSuperClass(); |
| 682 | DCHECK(java_lang_Object != NULL); |
| 683 | DCHECK(java_lang_Object->GetSuperClass() == NULL); |
| 684 | return this == java_lang_Object; |
| 685 | } |
| 686 | return IsArrayAssignableFromArray(klass); |
| 687 | } |
| 688 | |
| 689 | bool Class::IsSubClass(const Class* klass) const { |
| 690 | DCHECK(!IsInterface()); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 691 | DCHECK(!klass->IsArrayClass()); |
Brian Carlstrom | f7ed11a | 2011-08-09 17:55:51 -0700 | [diff] [blame] | 692 | const Class* current = this; |
| 693 | do { |
| 694 | if (current == klass) { |
| 695 | return true; |
| 696 | } |
| 697 | current = current->GetSuperClass(); |
| 698 | } while (current != NULL); |
| 699 | return false; |
| 700 | } |
| 701 | |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 702 | bool Class::IsInSamePackage(const String* descriptor_string_1, |
| 703 | const String* descriptor_string_2) { |
| 704 | const std::string descriptor1(descriptor_string_1->ToModifiedUtf8()); |
| 705 | const std::string descriptor2(descriptor_string_2->ToModifiedUtf8()); |
| 706 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 707 | size_t i = 0; |
| 708 | while (descriptor1[i] != '\0' && descriptor1[i] == descriptor2[i]) { |
| 709 | ++i; |
| 710 | } |
Brian Carlstrom | 6cc1845 | 2011-07-18 15:10:33 -0700 | [diff] [blame] | 711 | if (descriptor1.find('/', i) != StringPiece::npos || |
| 712 | descriptor2.find('/', i) != StringPiece::npos) { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 713 | return false; |
| 714 | } else { |
| 715 | return true; |
| 716 | } |
| 717 | } |
| 718 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 719 | #if 0 |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 720 | bool Class::IsInSamePackage(const StringPiece& descriptor1, |
| 721 | const StringPiece& descriptor2) { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 722 | size_t size = std::min(descriptor1.size(), descriptor2.size()); |
Brian Carlstrom | 6cc1845 | 2011-07-18 15:10:33 -0700 | [diff] [blame] | 723 | std::pair<StringPiece::const_iterator, StringPiece::const_iterator> pos; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 724 | pos = std::mismatch(descriptor1.begin(), descriptor1.begin() + size, |
| 725 | descriptor2.begin()); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 726 | return !(*(pos.second).rfind('/') != npos && descriptor2.rfind('/') != npos); |
| 727 | } |
| 728 | #endif |
| 729 | |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 730 | bool Class::IsInSamePackage(const Class* that) const { |
| 731 | const Class* klass1 = this; |
| 732 | const Class* klass2 = that; |
| 733 | if (klass1 == klass2) { |
| 734 | return true; |
| 735 | } |
| 736 | // Class loaders must match. |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 737 | if (klass1->GetClassLoader() != klass2->GetClassLoader()) { |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 738 | return false; |
| 739 | } |
| 740 | // Arrays are in the same package when their element classes are. |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 741 | if (klass1->IsArrayClass()) { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 742 | klass1 = klass1->GetComponentType(); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 743 | } |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 744 | if (klass2->IsArrayClass()) { |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 745 | klass2 = klass2->GetComponentType(); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 746 | } |
| 747 | // Compare the package part of the descriptor string. |
Brian Carlstrom | 6cc1845 | 2011-07-18 15:10:33 -0700 | [diff] [blame] | 748 | return IsInSamePackage(klass1->descriptor_, klass2->descriptor_); |
Carl Shapiro | 894d0fa | 2011-06-30 14:48:49 -0700 | [diff] [blame] | 749 | } |
| 750 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 751 | const ClassLoader* Class::GetClassLoader() const { |
| 752 | return GetFieldObject<const ClassLoader*>( |
| 753 | OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), false); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 756 | void Class::SetClassLoader(const ClassLoader* new_cl) { |
| 757 | ClassLoader* new_class_loader = const_cast<ClassLoader*>(new_cl); |
| 758 | SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Class, class_loader_), |
| 759 | new_class_loader, false); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 762 | Method* Class::FindVirtualMethodForInterface(Method* method) { |
| 763 | Class* declaring_class = method->GetDeclaringClass(); |
| 764 | DCHECK(declaring_class->IsInterface()); |
| 765 | // TODO cache to improve lookup speed |
| 766 | for (size_t i = 0; i < iftable_count_; i++) { |
| 767 | InterfaceEntry& interface_entry = iftable_[i]; |
| 768 | if (interface_entry.GetInterface() == declaring_class) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 769 | return GetVTable()->Get( |
| 770 | interface_entry.GetMethodIndexArray()[method->GetMethodIndex()]); |
Brian Carlstrom | 30b9445 | 2011-08-25 21:35:26 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | UNIMPLEMENTED(FATAL) << "Need to throw an error of some kind"; |
| 774 | return NULL; |
| 775 | } |
| 776 | |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 777 | Method* Class::FindInterfaceMethod(const StringPiece& name, |
| 778 | const StringPiece& signature) { |
| 779 | // Check the current class before checking the interfaces. |
| 780 | Method* method = FindVirtualMethod(name, signature); |
| 781 | if (method != NULL) { |
| 782 | return method; |
| 783 | } |
| 784 | |
| 785 | InterfaceEntry* iftable = GetIFTable(); |
| 786 | for (size_t i = 0; i < GetIFTableCount(); i++) { |
| 787 | method = iftable[i].GetInterface()->FindVirtualMethod(name, signature); |
| 788 | if (method != NULL) { |
| 789 | return method; |
| 790 | } |
| 791 | } |
| 792 | return NULL; |
| 793 | } |
| 794 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 795 | Method* Class::FindDeclaredDirectMethod(const StringPiece& name, |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 796 | const StringPiece& signature) { |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 797 | for (size_t i = 0; i < NumDirectMethods(); ++i) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 798 | Method* method = GetDirectMethod(i); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 799 | if (method->GetName()->Equals(name) && |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 800 | method->GetSignature()->Equals(signature)) { |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 801 | return method; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 802 | } |
| 803 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 804 | return NULL; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 807 | Method* Class::FindDirectMethod(const StringPiece& name, |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 808 | const StringPiece& signature) { |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 809 | for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 810 | Method* method = klass->FindDeclaredDirectMethod(name, signature); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 811 | if (method != NULL) { |
| 812 | return method; |
| 813 | } |
| 814 | } |
| 815 | return NULL; |
| 816 | } |
| 817 | |
| 818 | Method* Class::FindDeclaredVirtualMethod(const StringPiece& name, |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 819 | const StringPiece& signature) { |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 820 | for (size_t i = 0; i < NumVirtualMethods(); ++i) { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 821 | Method* method = GetVirtualMethod(i); |
Carl Shapiro | 8860c0e | 2011-08-04 17:36:16 -0700 | [diff] [blame] | 822 | if (method->GetName()->Equals(name) && |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 823 | method->GetSignature()->Equals(signature)) { |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 824 | return method; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 825 | } |
| 826 | } |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 827 | return NULL; |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 830 | Method* Class::FindVirtualMethod(const StringPiece& name, |
| 831 | const StringPiece& descriptor) { |
| 832 | for (Class* klass = this; klass != NULL; klass = klass->GetSuperClass()) { |
| 833 | Method* method = klass->FindDeclaredVirtualMethod(name, descriptor); |
| 834 | if (method != NULL) { |
| 835 | return method; |
| 836 | } |
| 837 | } |
| 838 | return NULL; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 839 | } |
| 840 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 841 | Field* Class::FindDeclaredInstanceField(const StringPiece& name, Class* type) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 842 | // Is the field in this class? |
| 843 | // Interfaces are not relevant because they can't contain instance fields. |
| 844 | for (size_t i = 0; i < NumInstanceFields(); ++i) { |
| 845 | Field* f = GetInstanceField(i); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 846 | if (f->GetName()->Equals(name) && type == f->GetType()) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 847 | return f; |
| 848 | } |
| 849 | } |
| 850 | return NULL; |
| 851 | } |
| 852 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 853 | Field* Class::FindInstanceField(const StringPiece& name, Class* type) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 854 | // Is the field in this class, or any of its superclasses? |
| 855 | // Interfaces are not relevant because they can't contain instance fields. |
| 856 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 857 | Field* f = c->FindDeclaredInstanceField(name, type); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 858 | if (f != NULL) { |
| 859 | return f; |
| 860 | } |
| 861 | } |
| 862 | return NULL; |
| 863 | } |
| 864 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 865 | Field* Class::FindDeclaredStaticField(const StringPiece& name, Class* type) { |
| 866 | DCHECK(type != NULL); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 867 | for (size_t i = 0; i < NumStaticFields(); ++i) { |
| 868 | Field* f = GetStaticField(i); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 869 | if (f->GetName()->Equals(name) && f->GetType() == type) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 870 | return f; |
| 871 | } |
| 872 | } |
| 873 | return NULL; |
| 874 | } |
| 875 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 876 | Field* Class::FindStaticField(const StringPiece& name, Class* type) { |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 877 | // Is the field in this class (or its interfaces), or any of its |
| 878 | // superclasses (or their interfaces)? |
| 879 | for (Class* c = this; c != NULL; c = c->GetSuperClass()) { |
| 880 | // Is the field in this class? |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 881 | Field* f = c->FindDeclaredStaticField(name, type); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 882 | if (f != NULL) { |
| 883 | return f; |
| 884 | } |
| 885 | |
| 886 | // Is this field in any of this class' interfaces? |
| 887 | for (size_t i = 0; i < c->NumInterfaces(); ++i) { |
| 888 | Class* interface = c->GetInterface(i); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 889 | f = interface->FindDeclaredStaticField(name, type); |
Elliott Hughes | cdf5312 | 2011-08-19 15:46:09 -0700 | [diff] [blame] | 890 | if (f != NULL) { |
| 891 | return f; |
| 892 | } |
| 893 | } |
| 894 | } |
| 895 | return NULL; |
| 896 | } |
| 897 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 898 | Array* Array::Alloc(Class* array_class, int32_t component_count, size_t component_size) { |
Elliott Hughes | 0f4c41d | 2011-09-04 14:58:03 -0700 | [diff] [blame] | 899 | DCHECK(array_class != NULL); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 900 | DCHECK_GE(component_count, 0); |
| 901 | DCHECK(array_class->IsArrayClass()); |
| 902 | size_t size = SizeOf(component_count, component_size); |
| 903 | Array* array = down_cast<Array*>(Heap::AllocObject(array_class, size)); |
| 904 | if (array != NULL) { |
| 905 | DCHECK(array->IsArrayInstance()); |
| 906 | array->SetLength(component_count); |
| 907 | } |
| 908 | return array; |
| 909 | } |
| 910 | |
| 911 | Array* Array::Alloc(Class* array_class, int32_t component_count) { |
| 912 | return Alloc(array_class, component_count, array_class->GetComponentSize()); |
| 913 | } |
| 914 | |
| 915 | Array* Array::AllocFromCode(uint32_t type_idx, Method* method, int32_t component_count) { |
| 916 | // TODO: throw on negative component_count |
| 917 | Class* klass = method->GetDexCacheResolvedTypes()->Get(type_idx); |
| 918 | if (klass == NULL) { |
| 919 | klass = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); |
| 920 | if (klass == NULL || !klass->IsArrayClass()) { |
| 921 | UNIMPLEMENTED(FATAL) << "throw an error"; |
| 922 | return NULL; |
| 923 | } |
| 924 | } |
| 925 | return Array::Alloc(klass, component_count); |
| 926 | } |
| 927 | |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 928 | template<typename T> |
| 929 | PrimitiveArray<T>* PrimitiveArray<T>::Alloc(size_t length) { |
Elliott Hughes | c1674ed | 2011-08-25 18:09:09 -0700 | [diff] [blame] | 930 | DCHECK(array_class_ != NULL); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 931 | Array* raw_array = Array::Alloc(array_class_, length, sizeof(T)); |
| 932 | return down_cast<PrimitiveArray<T>*>(raw_array); |
| 933 | } |
| 934 | |
| 935 | template <typename T> Class* PrimitiveArray<T>::array_class_ = NULL; |
| 936 | |
| 937 | // Explicitly instantiate all the primitive array types. |
| 938 | template class PrimitiveArray<uint8_t>; // BooleanArray |
| 939 | template class PrimitiveArray<int8_t>; // ByteArray |
| 940 | template class PrimitiveArray<uint16_t>; // CharArray |
| 941 | template class PrimitiveArray<double>; // DoubleArray |
| 942 | template class PrimitiveArray<float>; // FloatArray |
| 943 | template class PrimitiveArray<int32_t>; // IntArray |
| 944 | template class PrimitiveArray<int64_t>; // LongArray |
| 945 | template class PrimitiveArray<int16_t>; // ShortArray |
| 946 | |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 947 | // TODO: get global references for these |
| 948 | Class* String::java_lang_String_ = NULL; |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 949 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 950 | void String::SetClass(Class* java_lang_String) { |
| 951 | CHECK(java_lang_String_ == NULL); |
| 952 | CHECK(java_lang_String != NULL); |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 953 | java_lang_String_ = java_lang_String; |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 954 | } |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 955 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 956 | void String::ResetClass() { |
| 957 | CHECK(java_lang_String_ != NULL); |
| 958 | java_lang_String_ = NULL; |
| 959 | } |
Jesse Wilson | f7e85a5 | 2011-08-01 18:45:58 -0700 | [diff] [blame] | 960 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 961 | const String* String::Intern() const { |
| 962 | return Runtime::Current()->GetInternTable()->InternWeak(this); |
| 963 | } |
| 964 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 965 | int32_t String::GetHashCode() const { |
| 966 | int32_t result = GetField32( |
| 967 | OFFSET_OF_OBJECT_MEMBER(String, hash_code_), false); |
| 968 | DCHECK(result != 0 || |
| 969 | ComputeUtf16Hash(GetCharArray(), GetOffset(), GetLength()) == 0); |
| 970 | return result; |
| 971 | } |
| 972 | |
| 973 | int32_t String::GetLength() const { |
| 974 | int32_t result = GetField32(OFFSET_OF_OBJECT_MEMBER(String, count_), false); |
| 975 | DCHECK(result >= 0 && result <= GetCharArray()->GetLength()); |
| 976 | return result; |
| 977 | } |
| 978 | |
| 979 | uint16_t String::CharAt(int32_t index) const { |
| 980 | // TODO: do we need this? Equals is the only caller, and could |
| 981 | // bounds check itself. |
| 982 | if (index < 0 || index >= count_) { |
| 983 | Thread* self = Thread::Current(); |
| 984 | self->ThrowNewException("Ljava/lang/StringIndexOutOfBoundsException;", |
| 985 | "length=%i; index=%i", count_, index); |
| 986 | return 0; |
| 987 | } |
| 988 | return GetCharArray()->Get(index + GetOffset()); |
| 989 | } |
| 990 | |
| 991 | String* String::AllocFromUtf16(int32_t utf16_length, |
| 992 | const uint16_t* utf16_data_in, |
| 993 | int32_t hash_code) { |
| 994 | String* string = Alloc(GetJavaLangString(), utf16_length); |
| 995 | // TODO: use 16-bit wide memset variant |
| 996 | CharArray* array = const_cast<CharArray*>(string->GetCharArray()); |
| 997 | for (int i = 0; i < utf16_length; i++) { |
| 998 | array->Set(i, utf16_data_in[i]); |
| 999 | } |
| 1000 | if (hash_code != 0) { |
| 1001 | string->SetHashCode(hash_code); |
| 1002 | } else { |
| 1003 | string->ComputeHashCode(); |
| 1004 | } |
| 1005 | return string; |
| 1006 | } |
| 1007 | |
| 1008 | String* String::AllocFromModifiedUtf8(const char* utf) { |
| 1009 | size_t char_count = CountModifiedUtf8Chars(utf); |
| 1010 | return AllocFromModifiedUtf8(char_count, utf); |
| 1011 | } |
| 1012 | |
| 1013 | String* String::AllocFromModifiedUtf8(int32_t utf16_length, |
| 1014 | const char* utf8_data_in) { |
| 1015 | String* string = Alloc(GetJavaLangString(), utf16_length); |
| 1016 | uint16_t* utf16_data_out = |
| 1017 | const_cast<uint16_t*>(string->GetCharArray()->GetData()); |
| 1018 | ConvertModifiedUtf8ToUtf16(utf16_data_out, utf8_data_in); |
| 1019 | string->ComputeHashCode(); |
| 1020 | return string; |
| 1021 | } |
| 1022 | |
| 1023 | String* String::Alloc(Class* java_lang_String, int32_t utf16_length) { |
| 1024 | return Alloc(java_lang_String, CharArray::Alloc(utf16_length)); |
| 1025 | } |
| 1026 | |
| 1027 | String* String::Alloc(Class* java_lang_String, CharArray* array) { |
| 1028 | String* string = down_cast<String*>(java_lang_String->AllocObject()); |
| 1029 | string->SetArray(array); |
| 1030 | string->SetCount(array->GetLength()); |
| 1031 | return string; |
| 1032 | } |
| 1033 | |
| 1034 | bool String::Equals(const String* that) const { |
| 1035 | if (this == that) { |
| 1036 | // Quick reference equality test |
| 1037 | return true; |
| 1038 | } else if (that == NULL) { |
| 1039 | // Null isn't an instanceof anything |
| 1040 | return false; |
| 1041 | } else if (this->GetLength() != that->GetLength()) { |
| 1042 | // Quick length inequality test |
| 1043 | return false; |
| 1044 | } else { |
| 1045 | // NB don't short circuit on hash code as we're presumably here as the |
| 1046 | // hash code was already equal |
| 1047 | for (int32_t i = 0; i < that->GetLength(); ++i) { |
| 1048 | if (this->CharAt(i) != that->CharAt(i)) { |
| 1049 | return false; |
| 1050 | } |
| 1051 | } |
| 1052 | return true; |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | bool String::Equals(const uint16_t* that_chars, int32_t that_offset, |
| 1057 | int32_t that_length) const { |
| 1058 | if (this->GetLength() != that_length) { |
| 1059 | return false; |
| 1060 | } else { |
| 1061 | for (int32_t i = 0; i < that_length; ++i) { |
| 1062 | if (this->CharAt(i) != that_chars[that_offset + i]) { |
| 1063 | return false; |
| 1064 | } |
| 1065 | } |
| 1066 | return true; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | bool String::Equals(const char* modified_utf8) const { |
| 1071 | for (int32_t i = 0; i < GetLength(); ++i) { |
| 1072 | uint16_t ch = GetUtf16FromUtf8(&modified_utf8); |
| 1073 | if (ch == '\0' || ch != CharAt(i)) { |
| 1074 | return false; |
| 1075 | } |
| 1076 | } |
| 1077 | return *modified_utf8 == '\0'; |
| 1078 | } |
| 1079 | |
| 1080 | bool String::Equals(const StringPiece& modified_utf8) const { |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 1081 | // TODO: do not assume C-string representation. For now DCHECK. |
| 1082 | DCHECK_EQ(modified_utf8.data()[modified_utf8.size()], 0); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1083 | return Equals(modified_utf8.data()); |
| 1084 | } |
| 1085 | |
| 1086 | // Create a modified UTF-8 encoded std::string from a java/lang/String object. |
| 1087 | std::string String::ToModifiedUtf8() const { |
| 1088 | const uint16_t* chars = GetCharArray()->GetData() + GetOffset(); |
| 1089 | size_t byte_count(CountUtf8Bytes(chars, GetLength())); |
| 1090 | std::string result(byte_count, char(0)); |
| 1091 | ConvertUtf16ToModifiedUtf8(&result[0], chars, GetLength()); |
| 1092 | return result; |
| 1093 | } |
| 1094 | |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 1095 | Class* StackTraceElement::java_lang_StackTraceElement_ = NULL; |
| 1096 | |
| 1097 | void StackTraceElement::SetClass(Class* java_lang_StackTraceElement) { |
| 1098 | CHECK(java_lang_StackTraceElement_ == NULL); |
| 1099 | CHECK(java_lang_StackTraceElement != NULL); |
| 1100 | java_lang_StackTraceElement_ = java_lang_StackTraceElement; |
| 1101 | } |
| 1102 | |
| 1103 | void StackTraceElement::ResetClass() { |
| 1104 | CHECK(java_lang_StackTraceElement_ != NULL); |
| 1105 | java_lang_StackTraceElement_ = NULL; |
| 1106 | } |
| 1107 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 1108 | StackTraceElement* StackTraceElement::Alloc(const String* declaring_class, |
| 1109 | const String* method_name, |
| 1110 | const String* file_name, |
| 1111 | int32_t line_number) { |
| 1112 | StackTraceElement* trace = |
| 1113 | down_cast<StackTraceElement*>(GetStackTraceElement()->AllocObject()); |
| 1114 | trace->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, declaring_class_), |
| 1115 | const_cast<String*>(declaring_class), false); |
| 1116 | trace->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, method_name_), |
| 1117 | const_cast<String*>(method_name), false); |
| 1118 | trace->SetFieldObject(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, file_name_), |
| 1119 | const_cast<String*>(file_name), false); |
| 1120 | trace->SetField32(OFFSET_OF_OBJECT_MEMBER(StackTraceElement, line_number_), |
| 1121 | line_number, false); |
| 1122 | return trace; |
| 1123 | } |
| 1124 | |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 1125 | static const char* kClassStatusNames[] = { |
| 1126 | "Error", |
| 1127 | "NotReady", |
| 1128 | "Idx", |
| 1129 | "Loaded", |
| 1130 | "Resolved", |
| 1131 | "Verifying", |
| 1132 | "Verified", |
| 1133 | "Initializing", |
| 1134 | "Initialized" |
| 1135 | }; |
| 1136 | std::ostream& operator<<(std::ostream& os, const Class::Status& rhs) { |
| 1137 | if (rhs >= Class::kStatusError && rhs <= Class::kStatusInitialized) { |
Brian Carlstrom | ae3ac01 | 2011-07-27 01:30:28 -0700 | [diff] [blame] | 1138 | os << kClassStatusNames[rhs + 1]; |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 1139 | } else { |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 1140 | os << "Class::Status[" << static_cast<int>(rhs) << "]"; |
Elliott Hughes | 1f359b0 | 2011-07-17 14:27:17 -0700 | [diff] [blame] | 1141 | } |
| 1142 | return os; |
| 1143 | } |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1144 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 1145 | } // namespace art |