Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 11312183: - Do not mix scalar values and object fields in RawInstance to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 2891 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 // Load up a test script in the test library. 2902 // Load up a test script in the test library.
2903 2903
2904 // Invoke a function which returns an object of type NativeFields. 2904 // Invoke a function which returns an object of type NativeFields.
2905 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 2905 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
2906 EXPECT_VALID(result); 2906 EXPECT_VALID(result);
2907 DARTSCOPE_NOCHECKS(Isolate::Current()); 2907 DARTSCOPE_NOCHECKS(Isolate::Current());
2908 Instance& obj = Instance::Handle(); 2908 Instance& obj = Instance::Handle();
2909 obj ^= Api::UnwrapHandle(result); 2909 obj ^= Api::UnwrapHandle(result);
2910 const Class& cls = Class::Handle(obj.clazz()); 2910 const Class& cls = Class::Handle(obj.clazz());
2911 // We expect the newly created "NativeFields" object to have 2911 // We expect the newly created "NativeFields" object to have
2912 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. 2912 // 2 dart instance fields (fld1, fld2) and a reference to the native fields.
2913 // Hence the size of an instance of "NativeFields" should be 2913 // Hence the size of an instance of "NativeFields" should be
2914 // (kNumNativeFields + 2) * kWordSize + size of object header. 2914 // (1 + 2) * kWordSize + size of object header.
2915 // We check to make sure the instance size computed by the VM matches 2915 // We check to make sure the instance size computed by the VM matches
2916 // our expectations. 2916 // our expectations.
2917 intptr_t header_size = sizeof(RawObject); 2917 intptr_t header_size = sizeof(RawObject);
2918 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size, 2918 EXPECT_EQ(Utils::RoundUp(((1 + 2) * kWordSize) + header_size,
2919 kObjectAlignment), 2919 kObjectAlignment),
2920 cls.instance_size()); 2920 cls.instance_size());
2921 EXPECT_EQ(kNumNativeFields, cls.num_native_fields());
2921 } 2922 }
2922 2923
2923 2924
2924 TEST_CASE(InjectNativeFields2) { 2925 TEST_CASE(InjectNativeFields2) {
2925 const char* kScriptChars = 2926 const char* kScriptChars =
2926 "class NativeFields extends NativeFieldsWrapper {\n" 2927 "class NativeFields extends NativeFieldsWrapper {\n"
2927 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 2928 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
2928 " int fld1;\n" 2929 " int fld1;\n"
2929 " final int fld2;\n" 2930 " final int fld2;\n"
2930 " static int fld3;\n" 2931 " static int fld3;\n"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 native_field_lookup); 2971 native_field_lookup);
2971 2972
2972 // Invoke a function which returns an object of type NativeFields. 2973 // Invoke a function which returns an object of type NativeFields.
2973 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); 2974 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL);
2974 EXPECT_VALID(result); 2975 EXPECT_VALID(result);
2975 DARTSCOPE_NOCHECKS(Isolate::Current()); 2976 DARTSCOPE_NOCHECKS(Isolate::Current());
2976 Instance& obj = Instance::Handle(); 2977 Instance& obj = Instance::Handle();
2977 obj ^= Api::UnwrapHandle(result); 2978 obj ^= Api::UnwrapHandle(result);
2978 const Class& cls = Class::Handle(obj.clazz()); 2979 const Class& cls = Class::Handle(obj.clazz());
2979 // We expect the newly created "NativeFields" object to have 2980 // We expect the newly created "NativeFields" object to have
2980 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. 2981 // 2 dart instance fields (fld1, fld2) and a reference to the native fields.
2981 // Hence the size of an instance of "NativeFields" should be 2982 // Hence the size of an instance of "NativeFields" should be
2982 // (kNumNativeFields + 2) * kWordSize + size of object header. 2983 // (1 + 2) * kWordSize + size of object header.
2983 // We check to make sure the instance size computed by the VM matches 2984 // We check to make sure the instance size computed by the VM matches
2984 // our expectations. 2985 // our expectations.
2985 intptr_t header_size = sizeof(RawObject); 2986 intptr_t header_size = sizeof(RawObject);
2986 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size, 2987 EXPECT_EQ(Utils::RoundUp(((1 + 2) * kWordSize) + header_size,
2987 kObjectAlignment), 2988 kObjectAlignment),
2988 cls.instance_size()); 2989 cls.instance_size());
2990 EXPECT_EQ(kNumNativeFields, cls.num_native_fields());
2989 } 2991 }
2990 2992
2991 2993
2992 TEST_CASE(InjectNativeFields4) { 2994 TEST_CASE(InjectNativeFields4) {
2993 const char* kScriptChars = 2995 const char* kScriptChars =
2994 "#import('dart:nativewrappers');" 2996 "#import('dart:nativewrappers');"
2995 "class NativeFields extends NativeFieldWrapperClass2 {\n" 2997 "class NativeFields extends NativeFieldWrapperClass2 {\n"
2996 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 2998 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
2997 " int fld1;\n" 2999 " int fld1;\n"
2998 " final int fld2;\n" 3000 " final int fld2;\n"
(...skipping 4159 matching lines...) Expand 10 before | Expand all | Expand 10 after
7158 EXPECT(o2 == reinterpret_cast<void*>(&p2)); 7160 EXPECT(o2 == reinterpret_cast<void*>(&p2));
7159 } 7161 }
7160 Dart_ExitScope(); 7162 Dart_ExitScope();
7161 isolate->heap()->CollectGarbage(Heap::kOld); 7163 isolate->heap()->CollectGarbage(Heap::kOld);
7162 EXPECT_EQ(0, isolate->heap()->PeerCount()); 7164 EXPECT_EQ(0, isolate->heap()->PeerCount());
7163 } 7165 }
7164 7166
7165 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7167 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7166 7168
7167 } // namespace dart 7169 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698