OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/heap.h" | 10 #include "vm/heap.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // Implemented in the flow graph builder. | 35 // Implemented in the flow graph builder. |
36 UNREACHABLE(); | 36 UNREACHABLE(); |
37 return Object::null(); | 37 return Object::null(); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 DEFINE_NATIVE_ENTRY(Object_getHash, 1) { | 41 DEFINE_NATIVE_ENTRY(Object_getHash, 1) { |
42 // Please note that no handle is created for the argument. | 42 // Please note that no handle is created for the argument. |
43 // This is safe since the argument is only used in a tail call. | 43 // This is safe since the argument is only used in a tail call. |
44 // The performance benefit is more than 5% when using hashCode. | 44 // The performance benefit is more than 5% when using hashCode. |
| 45 #if defined(HASH_IN_OBJECT_HEADER) |
| 46 return Smi::New(Object::GetCachedHash(arguments->NativeArgAt(0))); |
| 47 #else |
45 Heap* heap = isolate->heap(); | 48 Heap* heap = isolate->heap(); |
46 ASSERT(arguments->NativeArgAt(0)->IsDartInstance()); | 49 ASSERT(arguments->NativeArgAt(0)->IsDartInstance()); |
47 return Smi::New(heap->GetHash(arguments->NativeArgAt(0))); | 50 return Smi::New(heap->GetHash(arguments->NativeArgAt(0))); |
| 51 #endif |
48 } | 52 } |
49 | 53 |
50 | 54 |
51 DEFINE_NATIVE_ENTRY(Object_setHash, 2) { | 55 DEFINE_NATIVE_ENTRY(Object_setHash, 2) { |
| 56 GET_NON_NULL_NATIVE_ARGUMENT(Smi, hash, arguments->NativeArgAt(1)); |
| 57 #if defined(HASH_IN_OBJECT_HEADER) |
| 58 Object::SetCachedHash(arguments->NativeArgAt(0), hash.Value()); |
| 59 #else |
52 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 60 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
53 GET_NON_NULL_NATIVE_ARGUMENT(Smi, hash, arguments->NativeArgAt(1)); | |
54 Heap* heap = isolate->heap(); | 61 Heap* heap = isolate->heap(); |
55 heap->SetHash(instance.raw(), hash.Value()); | 62 heap->SetHash(instance.raw(), hash.Value()); |
| 63 #endif |
56 return Object::null(); | 64 return Object::null(); |
57 } | 65 } |
58 | 66 |
59 | 67 |
60 DEFINE_NATIVE_ENTRY(Object_toString, 1) { | 68 DEFINE_NATIVE_ENTRY(Object_toString, 1) { |
61 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); | 69 const Instance& instance = Instance::CheckedHandle(arguments->NativeArgAt(0)); |
62 if (instance.IsString()) { | 70 if (instance.IsString()) { |
63 return instance.raw(); | 71 return instance.raw(); |
64 } | 72 } |
65 const char* c_str = instance.ToCString(); | 73 const char* c_str = instance.ToCString(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 for (intptr_t i = split; i < len; i++) { | 393 for (intptr_t i = split; i < len; i++) { |
386 type = function_type_arguments.IsNull() | 394 type = function_type_arguments.IsNull() |
387 ? Type::DynamicType() | 395 ? Type::DynamicType() |
388 : function_type_arguments.TypeAt(i - split); | 396 : function_type_arguments.TypeAt(i - split); |
389 result.SetTypeAt(i, type); | 397 result.SetTypeAt(i, type); |
390 } | 398 } |
391 return result.Canonicalize(); | 399 return result.Canonicalize(); |
392 } | 400 } |
393 | 401 |
394 } // namespace dart | 402 } // namespace dart |
OLD | NEW |