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

Side by Side Diff: test/cctest/test-heap.cc

Issue 1413463006: Map v8::Object to v8::internal::JSReceiver (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2600 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 2611
2612 2612
2613 TEST(PrototypeTransitionClearing) { 2613 TEST(PrototypeTransitionClearing) {
2614 if (FLAG_never_compact) return; 2614 if (FLAG_never_compact) return;
2615 CcTest::InitializeVM(); 2615 CcTest::InitializeVM();
2616 Isolate* isolate = CcTest::i_isolate(); 2616 Isolate* isolate = CcTest::i_isolate();
2617 Factory* factory = isolate->factory(); 2617 Factory* factory = isolate->factory();
2618 v8::HandleScope scope(CcTest::isolate()); 2618 v8::HandleScope scope(CcTest::isolate());
2619 2619
2620 CompileRun("var base = {};"); 2620 CompileRun("var base = {};");
2621 Handle<JSObject> baseObject = 2621 Handle<JSReceiver> baseObject = v8::Utils::OpenHandle(
2622 v8::Utils::OpenHandle( 2622 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("base"))));
2623 *v8::Handle<v8::Object>::Cast(
2624 CcTest::global()->Get(v8_str("base"))));
2625 int initialTransitions = NumberOfProtoTransitions(baseObject->map()); 2623 int initialTransitions = NumberOfProtoTransitions(baseObject->map());
2626 2624
2627 CompileRun( 2625 CompileRun(
2628 "var live = [];" 2626 "var live = [];"
2629 "for (var i = 0; i < 10; i++) {" 2627 "for (var i = 0; i < 10; i++) {"
2630 " var object = {};" 2628 " var object = {};"
2631 " var prototype = {};" 2629 " var prototype = {};"
2632 " object.__proto__ = prototype;" 2630 " object.__proto__ = prototype;"
2633 " if (i >= 3) live.push(object, prototype);" 2631 " if (i >= 3) live.push(object, prototype);"
2634 "}"); 2632 "}");
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2844 " this['x' + i] = x;" 2842 " this['x' + i] = x;"
2845 " }" 2843 " }"
2846 "}" 2844 "}"
2847 "function f(x) { return new c(x); };" 2845 "function f(x) { return new c(x); };"
2848 "f(1); f(2); f(3);" 2846 "f(1); f(2); f(3);"
2849 "%OptimizeFunctionOnNextCall(f);" 2847 "%OptimizeFunctionOnNextCall(f);"
2850 "f(4);"); 2848 "f(4);");
2851 CHECK_EQ( 2849 CHECK_EQ(
2852 4, res.As<v8::Object>()->GetRealNamedProperty(v8_str("x"))->Int32Value()); 2850 4, res.As<v8::Object>()->GetRealNamedProperty(v8_str("x"))->Int32Value());
2853 2851
2854 Handle<JSObject> o = 2852 Handle<JSReceiver> o =
2855 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2853 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
2856 2854
2857 CHECK(CcTest::heap()->InNewSpace(*o)); 2855 CHECK(CcTest::heap()->InNewSpace(*o));
2858 } 2856 }
2859 2857
2860 2858
2861 TEST(OptimizedPretenuringAllocationFolding) { 2859 TEST(OptimizedPretenuringAllocationFolding) {
2862 i::FLAG_allow_natives_syntax = true; 2860 i::FLAG_allow_natives_syntax = true;
2863 i::FLAG_expose_gc = true; 2861 i::FLAG_expose_gc = true;
2864 CcTest::InitializeVM(); 2862 CcTest::InitializeVM();
(...skipping 19 matching lines...) Expand all
2884 "};" 2882 "};"
2885 "f(); gc();" 2883 "f(); gc();"
2886 "f(); f();" 2884 "f(); f();"
2887 "%%OptimizeFunctionOnNextCall(f);" 2885 "%%OptimizeFunctionOnNextCall(f);"
2888 "f();", 2886 "f();",
2889 AllocationSite::kPretenureMinimumCreated); 2887 AllocationSite::kPretenureMinimumCreated);
2890 2888
2891 v8::Local<v8::Value> res = CompileRun(source.start()); 2889 v8::Local<v8::Value> res = CompileRun(source.start());
2892 2890
2893 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); 2891 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0"));
2894 Handle<JSObject> int_array_handle = 2892 Handle<JSObject> int_array_handle = Handle<JSObject>::cast(
2895 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); 2893 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)));
2896 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); 2894 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1"));
2897 Handle<JSObject> double_array_handle = 2895 Handle<JSObject> double_array_handle = Handle<JSObject>::cast(
2898 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); 2896 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)));
2899 2897
2900 Handle<JSObject> o = 2898 Handle<JSReceiver> o =
2901 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2899 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
2902 CHECK(CcTest::heap()->InOldSpace(*o)); 2900 CHECK(CcTest::heap()->InOldSpace(*o));
2903 CHECK(CcTest::heap()->InOldSpace(*int_array_handle)); 2901 CHECK(CcTest::heap()->InOldSpace(*int_array_handle));
2904 CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements())); 2902 CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements()));
2905 CHECK(CcTest::heap()->InOldSpace(*double_array_handle)); 2903 CHECK(CcTest::heap()->InOldSpace(*double_array_handle));
2906 CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements())); 2904 CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements()));
2907 } 2905 }
2908 2906
2909 2907
2910 TEST(OptimizedPretenuringObjectArrayLiterals) { 2908 TEST(OptimizedPretenuringObjectArrayLiterals) {
(...skipping 21 matching lines...) Expand all
2932 " return elements[number_elements - 1];" 2930 " return elements[number_elements - 1];"
2933 "};" 2931 "};"
2934 "f(); gc();" 2932 "f(); gc();"
2935 "f(); f();" 2933 "f(); f();"
2936 "%%OptimizeFunctionOnNextCall(f);" 2934 "%%OptimizeFunctionOnNextCall(f);"
2937 "f();", 2935 "f();",
2938 AllocationSite::kPretenureMinimumCreated); 2936 AllocationSite::kPretenureMinimumCreated);
2939 2937
2940 v8::Local<v8::Value> res = CompileRun(source.start()); 2938 v8::Local<v8::Value> res = CompileRun(source.start());
2941 2939
2942 Handle<JSObject> o = 2940 Handle<JSObject> o = Handle<JSObject>::cast(
2943 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2941 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
2944 2942
2945 CHECK(CcTest::heap()->InOldSpace(o->elements())); 2943 CHECK(CcTest::heap()->InOldSpace(o->elements()));
2946 CHECK(CcTest::heap()->InOldSpace(*o)); 2944 CHECK(CcTest::heap()->InOldSpace(*o));
2947 } 2945 }
2948 2946
2949 2947
2950 TEST(OptimizedPretenuringMixedInObjectProperties) { 2948 TEST(OptimizedPretenuringMixedInObjectProperties) {
2951 i::FLAG_allow_natives_syntax = true; 2949 i::FLAG_allow_natives_syntax = true;
2952 i::FLAG_expose_gc = true; 2950 i::FLAG_expose_gc = true;
2953 CcTest::InitializeVM(); 2951 CcTest::InitializeVM();
(...skipping 19 matching lines...) Expand all
2973 " return elements[number_elements - 1];" 2971 " return elements[number_elements - 1];"
2974 "};" 2972 "};"
2975 "f(); gc();" 2973 "f(); gc();"
2976 "f(); f();" 2974 "f(); f();"
2977 "%%OptimizeFunctionOnNextCall(f);" 2975 "%%OptimizeFunctionOnNextCall(f);"
2978 "f();", 2976 "f();",
2979 AllocationSite::kPretenureMinimumCreated); 2977 AllocationSite::kPretenureMinimumCreated);
2980 2978
2981 v8::Local<v8::Value> res = CompileRun(source.start()); 2979 v8::Local<v8::Value> res = CompileRun(source.start());
2982 2980
2983 Handle<JSObject> o = 2981 Handle<JSObject> o = Handle<JSObject>::cast(
2984 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 2982 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
2985 2983
2986 CHECK(CcTest::heap()->InOldSpace(*o)); 2984 CHECK(CcTest::heap()->InOldSpace(*o));
2987 FieldIndex idx1 = FieldIndex::ForPropertyIndex(o->map(), 0); 2985 FieldIndex idx1 = FieldIndex::ForPropertyIndex(o->map(), 0);
2988 FieldIndex idx2 = FieldIndex::ForPropertyIndex(o->map(), 1); 2986 FieldIndex idx2 = FieldIndex::ForPropertyIndex(o->map(), 1);
2989 CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx1))); 2987 CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx1)));
2990 if (!o->IsUnboxedDoubleField(idx2)) { 2988 if (!o->IsUnboxedDoubleField(idx2)) {
2991 CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx2))); 2989 CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx2)));
2992 } else { 2990 } else {
2993 CHECK_EQ(1.1, o->RawFastDoublePropertyAt(idx2)); 2991 CHECK_EQ(1.1, o->RawFastDoublePropertyAt(idx2));
2994 } 2992 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 " return elements[i - 1];" 3028 " return elements[i - 1];"
3031 "};" 3029 "};"
3032 "f(); gc();" 3030 "f(); gc();"
3033 "f(); f();" 3031 "f(); f();"
3034 "%%OptimizeFunctionOnNextCall(f);" 3032 "%%OptimizeFunctionOnNextCall(f);"
3035 "f();", 3033 "f();",
3036 AllocationSite::kPretenureMinimumCreated); 3034 AllocationSite::kPretenureMinimumCreated);
3037 3035
3038 v8::Local<v8::Value> res = CompileRun(source.start()); 3036 v8::Local<v8::Value> res = CompileRun(source.start());
3039 3037
3040 Handle<JSObject> o = 3038 Handle<JSObject> o = Handle<JSObject>::cast(
3041 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3039 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3042 3040
3043 CHECK(CcTest::heap()->InOldSpace(*o)); 3041 CHECK(CcTest::heap()->InOldSpace(*o));
3044 CHECK(CcTest::heap()->InOldSpace(o->properties())); 3042 CHECK(CcTest::heap()->InOldSpace(o->properties()));
3045 } 3043 }
3046 3044
3047 3045
3048 TEST(OptimizedPretenuringdoubleArrayLiterals) { 3046 TEST(OptimizedPretenuringdoubleArrayLiterals) {
3049 i::FLAG_allow_natives_syntax = true; 3047 i::FLAG_allow_natives_syntax = true;
3050 i::FLAG_expose_gc = true; 3048 i::FLAG_expose_gc = true;
3051 CcTest::InitializeVM(); 3049 CcTest::InitializeVM();
(...skipping 18 matching lines...) Expand all
3070 " return elements[number_elements - 1];" 3068 " return elements[number_elements - 1];"
3071 "};" 3069 "};"
3072 "f(); gc();" 3070 "f(); gc();"
3073 "f(); f();" 3071 "f(); f();"
3074 "%%OptimizeFunctionOnNextCall(f);" 3072 "%%OptimizeFunctionOnNextCall(f);"
3075 "f();", 3073 "f();",
3076 AllocationSite::kPretenureMinimumCreated); 3074 AllocationSite::kPretenureMinimumCreated);
3077 3075
3078 v8::Local<v8::Value> res = CompileRun(source.start()); 3076 v8::Local<v8::Value> res = CompileRun(source.start());
3079 3077
3080 Handle<JSObject> o = 3078 Handle<JSObject> o = Handle<JSObject>::cast(
3081 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3079 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3082 3080
3083 CHECK(CcTest::heap()->InOldSpace(o->elements())); 3081 CHECK(CcTest::heap()->InOldSpace(o->elements()));
3084 CHECK(CcTest::heap()->InOldSpace(*o)); 3082 CHECK(CcTest::heap()->InOldSpace(*o));
3085 } 3083 }
3086 3084
3087 3085
3088 TEST(OptimizedPretenuringNestedMixedArrayLiterals) { 3086 TEST(OptimizedPretenuringNestedMixedArrayLiterals) {
3089 i::FLAG_allow_natives_syntax = true; 3087 i::FLAG_allow_natives_syntax = true;
3090 i::FLAG_expose_gc = true; 3088 i::FLAG_expose_gc = true;
3091 CcTest::InitializeVM(); 3089 CcTest::InitializeVM();
(...skipping 18 matching lines...) Expand all
3110 " return elements[number_elements - 1];" 3108 " return elements[number_elements - 1];"
3111 "};" 3109 "};"
3112 "f(); gc();" 3110 "f(); gc();"
3113 "f(); f();" 3111 "f(); f();"
3114 "%%OptimizeFunctionOnNextCall(f);" 3112 "%%OptimizeFunctionOnNextCall(f);"
3115 "f();"); 3113 "f();");
3116 3114
3117 v8::Local<v8::Value> res = CompileRun(source.start()); 3115 v8::Local<v8::Value> res = CompileRun(source.start());
3118 3116
3119 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0")); 3117 v8::Local<v8::Value> int_array = v8::Object::Cast(*res)->Get(v8_str("0"));
3120 Handle<JSObject> int_array_handle = 3118 Handle<JSObject> int_array_handle = Handle<JSObject>::cast(
3121 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)); 3119 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array)));
3122 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1")); 3120 v8::Local<v8::Value> double_array = v8::Object::Cast(*res)->Get(v8_str("1"));
3123 Handle<JSObject> double_array_handle = 3121 Handle<JSObject> double_array_handle = Handle<JSObject>::cast(
3124 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)); 3122 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array)));
3125 3123
3126 Handle<JSObject> o = 3124 Handle<JSObject> o = Handle<JSObject>::cast(
3127 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3125 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3128 CHECK(CcTest::heap()->InOldSpace(*o)); 3126 CHECK(CcTest::heap()->InOldSpace(*o));
3129 CHECK(CcTest::heap()->InOldSpace(*int_array_handle)); 3127 CHECK(CcTest::heap()->InOldSpace(*int_array_handle));
3130 CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements())); 3128 CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements()));
3131 CHECK(CcTest::heap()->InOldSpace(*double_array_handle)); 3129 CHECK(CcTest::heap()->InOldSpace(*double_array_handle));
3132 CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements())); 3130 CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements()));
3133 } 3131 }
3134 3132
3135 3133
3136 TEST(OptimizedPretenuringNestedObjectLiterals) { 3134 TEST(OptimizedPretenuringNestedObjectLiterals) {
3137 i::FLAG_allow_natives_syntax = true; 3135 i::FLAG_allow_natives_syntax = true;
(...skipping 21 matching lines...) Expand all
3159 "};" 3157 "};"
3160 "f(); gc();" 3158 "f(); gc();"
3161 "f(); f();" 3159 "f(); f();"
3162 "%%OptimizeFunctionOnNextCall(f);" 3160 "%%OptimizeFunctionOnNextCall(f);"
3163 "f();", 3161 "f();",
3164 AllocationSite::kPretenureMinimumCreated); 3162 AllocationSite::kPretenureMinimumCreated);
3165 3163
3166 v8::Local<v8::Value> res = CompileRun(source.start()); 3164 v8::Local<v8::Value> res = CompileRun(source.start());
3167 3165
3168 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0")); 3166 v8::Local<v8::Value> int_array_1 = v8::Object::Cast(*res)->Get(v8_str("0"));
3169 Handle<JSObject> int_array_handle_1 = 3167 Handle<JSObject> int_array_handle_1 = Handle<JSObject>::cast(
3170 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)); 3168 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_1)));
3171 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1")); 3169 v8::Local<v8::Value> int_array_2 = v8::Object::Cast(*res)->Get(v8_str("1"));
3172 Handle<JSObject> int_array_handle_2 = 3170 Handle<JSObject> int_array_handle_2 = Handle<JSObject>::cast(
3173 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)); 3171 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(int_array_2)));
3174 3172
3175 Handle<JSObject> o = 3173 Handle<JSObject> o = Handle<JSObject>::cast(
3176 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3174 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3177 CHECK(CcTest::heap()->InOldSpace(*o)); 3175 CHECK(CcTest::heap()->InOldSpace(*o));
3178 CHECK(CcTest::heap()->InOldSpace(*int_array_handle_1)); 3176 CHECK(CcTest::heap()->InOldSpace(*int_array_handle_1));
3179 CHECK(CcTest::heap()->InOldSpace(int_array_handle_1->elements())); 3177 CHECK(CcTest::heap()->InOldSpace(int_array_handle_1->elements()));
3180 CHECK(CcTest::heap()->InOldSpace(*int_array_handle_2)); 3178 CHECK(CcTest::heap()->InOldSpace(*int_array_handle_2));
3181 CHECK(CcTest::heap()->InOldSpace(int_array_handle_2->elements())); 3179 CHECK(CcTest::heap()->InOldSpace(int_array_handle_2->elements()));
3182 } 3180 }
3183 3181
3184 3182
3185 TEST(OptimizedPretenuringNestedDoubleLiterals) { 3183 TEST(OptimizedPretenuringNestedDoubleLiterals) {
3186 i::FLAG_allow_natives_syntax = true; 3184 i::FLAG_allow_natives_syntax = true;
(...skipping 22 matching lines...) Expand all
3209 "f(); gc();" 3207 "f(); gc();"
3210 "f(); f();" 3208 "f(); f();"
3211 "%%OptimizeFunctionOnNextCall(f);" 3209 "%%OptimizeFunctionOnNextCall(f);"
3212 "f();", 3210 "f();",
3213 AllocationSite::kPretenureMinimumCreated); 3211 AllocationSite::kPretenureMinimumCreated);
3214 3212
3215 v8::Local<v8::Value> res = CompileRun(source.start()); 3213 v8::Local<v8::Value> res = CompileRun(source.start());
3216 3214
3217 v8::Local<v8::Value> double_array_1 = 3215 v8::Local<v8::Value> double_array_1 =
3218 v8::Object::Cast(*res)->Get(v8_str("0")); 3216 v8::Object::Cast(*res)->Get(v8_str("0"));
3219 Handle<JSObject> double_array_handle_1 = 3217 Handle<JSObject> double_array_handle_1 = Handle<JSObject>::cast(
3220 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)); 3218 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_1)));
3221 v8::Local<v8::Value> double_array_2 = 3219 v8::Local<v8::Value> double_array_2 =
3222 v8::Object::Cast(*res)->Get(v8_str("1")); 3220 v8::Object::Cast(*res)->Get(v8_str("1"));
3223 Handle<JSObject> double_array_handle_2 = 3221 Handle<JSObject> double_array_handle_2 = Handle<JSObject>::cast(
3224 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)); 3222 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(double_array_2)));
3225 3223
3226 Handle<JSObject> o = 3224 Handle<JSObject> o = Handle<JSObject>::cast(
3227 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3225 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3228 CHECK(CcTest::heap()->InOldSpace(*o)); 3226 CHECK(CcTest::heap()->InOldSpace(*o));
3229 CHECK(CcTest::heap()->InOldSpace(*double_array_handle_1)); 3227 CHECK(CcTest::heap()->InOldSpace(*double_array_handle_1));
3230 CHECK(CcTest::heap()->InOldSpace(double_array_handle_1->elements())); 3228 CHECK(CcTest::heap()->InOldSpace(double_array_handle_1->elements()));
3231 CHECK(CcTest::heap()->InOldSpace(*double_array_handle_2)); 3229 CHECK(CcTest::heap()->InOldSpace(*double_array_handle_2));
3232 CHECK(CcTest::heap()->InOldSpace(double_array_handle_2->elements())); 3230 CHECK(CcTest::heap()->InOldSpace(double_array_handle_2->elements()));
3233 } 3231 }
3234 3232
3235 3233
3236 // Test regular array literals allocation. 3234 // Test regular array literals allocation.
3237 TEST(OptimizedAllocationArrayLiterals) { 3235 TEST(OptimizedAllocationArrayLiterals) {
3238 i::FLAG_allow_natives_syntax = true; 3236 i::FLAG_allow_natives_syntax = true;
3239 CcTest::InitializeVM(); 3237 CcTest::InitializeVM();
3240 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return; 3238 if (!CcTest::i_isolate()->use_crankshaft() || i::FLAG_always_opt) return;
3241 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return; 3239 if (i::FLAG_gc_global || i::FLAG_stress_compaction) return;
3242 v8::HandleScope scope(CcTest::isolate()); 3240 v8::HandleScope scope(CcTest::isolate());
3243 3241
3244 v8::Local<v8::Value> res = CompileRun( 3242 v8::Local<v8::Value> res = CompileRun(
3245 "function f() {" 3243 "function f() {"
3246 " var numbers = new Array(1, 2, 3);" 3244 " var numbers = new Array(1, 2, 3);"
3247 " numbers[0] = 3.14;" 3245 " numbers[0] = 3.14;"
3248 " return numbers;" 3246 " return numbers;"
3249 "};" 3247 "};"
3250 "f(); f(); f();" 3248 "f(); f(); f();"
3251 "%OptimizeFunctionOnNextCall(f);" 3249 "%OptimizeFunctionOnNextCall(f);"
3252 "f();"); 3250 "f();");
3253 CHECK_EQ(static_cast<int>(3.14), 3251 CHECK_EQ(static_cast<int>(3.14),
3254 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value()); 3252 v8::Object::Cast(*res)->Get(v8_str("0"))->Int32Value());
3255 3253
3256 Handle<JSObject> o = 3254 Handle<JSObject> o = Handle<JSObject>::cast(
3257 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3255 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)));
3258 3256
3259 CHECK(CcTest::heap()->InNewSpace(o->elements())); 3257 CHECK(CcTest::heap()->InNewSpace(o->elements()));
3260 } 3258 }
3261 3259
3262 3260
3263 static int CountMapTransitions(Map* map) { 3261 static int CountMapTransitions(Map* map) {
3264 return TransitionArray::NumberOfTransitions(map->raw_transitions()); 3262 return TransitionArray::NumberOfTransitions(map->raw_transitions());
3265 } 3263 }
3266 3264
3267 3265
(...skipping 12 matching lines...) Expand all
3280 { 3278 {
3281 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 3279 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
3282 for (int i = 0; i < transitions_count; i++) { 3280 for (int i = 0; i < transitions_count; i++) {
3283 EmbeddedVector<char, 64> buffer; 3281 EmbeddedVector<char, 64> buffer;
3284 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); 3282 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
3285 CompileRun(buffer.start()); 3283 CompileRun(buffer.start());
3286 } 3284 }
3287 CompileRun("var root = new F;"); 3285 CompileRun("var root = new F;");
3288 } 3286 }
3289 3287
3290 Handle<JSObject> root = 3288 Handle<JSReceiver> root = v8::Utils::OpenHandle(
3291 v8::Utils::OpenHandle( 3289 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("root"))));
3292 *v8::Handle<v8::Object>::Cast(
3293 CcTest::global()->Get(v8_str("root"))));
3294 3290
3295 // Count number of live transitions before marking. 3291 // Count number of live transitions before marking.
3296 int transitions_before = CountMapTransitions(root->map()); 3292 int transitions_before = CountMapTransitions(root->map());
3297 CompileRun("%DebugPrint(root);"); 3293 CompileRun("%DebugPrint(root);");
3298 CHECK_EQ(transitions_count, transitions_before); 3294 CHECK_EQ(transitions_count, transitions_before);
3299 3295
3300 SimulateIncrementalMarking(CcTest::heap()); 3296 SimulateIncrementalMarking(CcTest::heap());
3301 CcTest::heap()->CollectAllGarbage(); 3297 CcTest::heap()->CollectAllGarbage();
3302 3298
3303 // Count number of live transitions after marking. Note that one transition 3299 // Count number of live transitions after marking. Note that one transition
3304 // is left, because 'o' still holds an instance of one transition target. 3300 // is left, because 'o' still holds an instance of one transition target.
3305 int transitions_after = CountMapTransitions(root->map()); 3301 int transitions_after = CountMapTransitions(root->map());
3306 CompileRun("%DebugPrint(root);"); 3302 CompileRun("%DebugPrint(root);");
3307 CHECK_EQ(1, transitions_after); 3303 CHECK_EQ(1, transitions_after);
3308 } 3304 }
3309 3305
3310 3306
3311 #ifdef DEBUG 3307 #ifdef DEBUG
3312 static void AddTransitions(int transitions_count) { 3308 static void AddTransitions(int transitions_count) {
3313 AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 3309 AlwaysAllocateScope always_allocate(CcTest::i_isolate());
3314 for (int i = 0; i < transitions_count; i++) { 3310 for (int i = 0; i < transitions_count; i++) {
3315 EmbeddedVector<char, 64> buffer; 3311 EmbeddedVector<char, 64> buffer;
3316 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i); 3312 SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
3317 CompileRun(buffer.start()); 3313 CompileRun(buffer.start());
3318 } 3314 }
3319 } 3315 }
3320 3316
3321 3317
3322 static Handle<JSObject> GetByName(const char* name) { 3318 static Handle<JSObject> GetByName(const char* name) {
3323 return v8::Utils::OpenHandle( 3319 return Handle<JSObject>::cast(v8::Utils::OpenHandle(
3324 *v8::Handle<v8::Object>::Cast( 3320 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str(name)))));
3325 CcTest::global()->Get(v8_str(name))));
3326 } 3321 }
3327 3322
3328 3323
3329 static void AddPropertyTo( 3324 static void AddPropertyTo(
3330 int gc_count, Handle<JSObject> object, const char* property_name) { 3325 int gc_count, Handle<JSObject> object, const char* property_name) {
3331 Isolate* isolate = CcTest::i_isolate(); 3326 Isolate* isolate = CcTest::i_isolate();
3332 Factory* factory = isolate->factory(); 3327 Factory* factory = isolate->factory();
3333 Handle<String> prop_name = factory->InternalizeUtf8String(property_name); 3328 Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
3334 Handle<Smi> twenty_three(Smi::FromInt(23), isolate); 3329 Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
3335 i::FLAG_gc_interval = gc_count; 3330 i::FLAG_gc_interval = gc_count;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 "}" 3470 "}"
3476 "f(new Object);" 3471 "f(new Object);"
3477 "f(root);"); 3472 "f(root);");
3478 3473
3479 // This bug only triggers with aggressive IC clearing. 3474 // This bug only triggers with aggressive IC clearing.
3480 CcTest::heap()->AgeInlineCaches(); 3475 CcTest::heap()->AgeInlineCaches();
3481 3476
3482 // Explicitly request GC to perform final marking step and sweeping. 3477 // Explicitly request GC to perform final marking step and sweeping.
3483 CcTest::heap()->CollectAllGarbage(); 3478 CcTest::heap()->CollectAllGarbage();
3484 3479
3485 Handle<JSObject> root = 3480 Handle<JSReceiver> root = v8::Utils::OpenHandle(
3486 v8::Utils::OpenHandle( 3481 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("root"))));
3487 *v8::Handle<v8::Object>::Cast(
3488 CcTest::global()->Get(v8_str("root"))));
3489 3482
3490 // The root object should be in a sane state. 3483 // The root object should be in a sane state.
3491 CHECK(root->IsJSObject()); 3484 CHECK(root->IsJSObject());
3492 CHECK(root->map()->IsMap()); 3485 CHECK(root->map()->IsMap());
3493 } 3486 }
3494 3487
3495 3488
3496 TEST(Regress2143b) { 3489 TEST(Regress2143b) {
3497 i::FLAG_incremental_marking = true; 3490 i::FLAG_incremental_marking = true;
3498 i::FLAG_allow_natives_syntax = true; 3491 i::FLAG_allow_natives_syntax = true;
(...skipping 19 matching lines...) Expand all
3518 "%OptimizeFunctionOnNextCall(f);" 3511 "%OptimizeFunctionOnNextCall(f);"
3519 "f(root);" 3512 "f(root);"
3520 "%DeoptimizeFunction(f);"); 3513 "%DeoptimizeFunction(f);");
3521 3514
3522 // This bug only triggers with aggressive IC clearing. 3515 // This bug only triggers with aggressive IC clearing.
3523 CcTest::heap()->AgeInlineCaches(); 3516 CcTest::heap()->AgeInlineCaches();
3524 3517
3525 // Explicitly request GC to perform final marking step and sweeping. 3518 // Explicitly request GC to perform final marking step and sweeping.
3526 CcTest::heap()->CollectAllGarbage(); 3519 CcTest::heap()->CollectAllGarbage();
3527 3520
3528 Handle<JSObject> root = 3521 Handle<JSReceiver> root = v8::Utils::OpenHandle(
3529 v8::Utils::OpenHandle( 3522 *v8::Handle<v8::Object>::Cast(CcTest::global()->Get(v8_str("root"))));
3530 *v8::Handle<v8::Object>::Cast(
3531 CcTest::global()->Get(v8_str("root"))));
3532 3523
3533 // The root object should be in a sane state. 3524 // The root object should be in a sane state.
3534 CHECK(root->IsJSObject()); 3525 CHECK(root->IsJSObject());
3535 CHECK(root->map()->IsMap()); 3526 CHECK(root->map()->IsMap());
3536 } 3527 }
3537 3528
3538 3529
3539 TEST(ReleaseOverReservedPages) { 3530 TEST(ReleaseOverReservedPages) {
3540 if (FLAG_never_compact) return; 3531 if (FLAG_never_compact) return;
3541 i::FLAG_trace_gc = true; 3532 i::FLAG_trace_gc = true;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
3718 3709
3719 TEST(ICInBuiltInIsClearedAppropriately) { 3710 TEST(ICInBuiltInIsClearedAppropriately) {
3720 if (i::FLAG_always_opt) return; 3711 if (i::FLAG_always_opt) return;
3721 CcTest::InitializeVM(); 3712 CcTest::InitializeVM();
3722 v8::HandleScope scope(CcTest::isolate()); 3713 v8::HandleScope scope(CcTest::isolate());
3723 3714
3724 Handle<JSFunction> apply; 3715 Handle<JSFunction> apply;
3725 { 3716 {
3726 LocalContext env; 3717 LocalContext env;
3727 v8::Local<v8::Value> res = CompileRun("Function.apply"); 3718 v8::Local<v8::Value> res = CompileRun("Function.apply");
3728 Handle<JSObject> maybe_apply = 3719 Handle<JSReceiver> maybe_apply =
3729 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res)); 3720 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(res));
3730 apply = Handle<JSFunction>::cast(maybe_apply); 3721 apply = Handle<JSFunction>::cast(maybe_apply);
3731 Handle<TypeFeedbackVector> vector(apply->shared()->feedback_vector()); 3722 Handle<TypeFeedbackVector> vector(apply->shared()->feedback_vector());
3732 FeedbackVectorHelper feedback_helper(vector); 3723 FeedbackVectorHelper feedback_helper(vector);
3733 CHECK_EQ(1, feedback_helper.slot_count()); 3724 CHECK_EQ(1, feedback_helper.slot_count());
3734 CheckVectorIC(apply, 0, UNINITIALIZED); 3725 CheckVectorIC(apply, 0, UNINITIALIZED);
3735 CompileRun( 3726 CompileRun(
3736 "function b(a1, a2, a3) { return a1 + a2 + a3; }" 3727 "function b(a1, a2, a3) { return a1 + a2 + a3; }"
3737 "function fun(bar) { bar.apply({}, [1, 2, 3]); };" 3728 "function fun(bar) { bar.apply({}, [1, 2, 3]); };"
3738 "fun(b); fun(b)"); 3729 "fun(b); fun(b)");
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
5466 5457
5467 v8::Local<v8::Value> result = CompileRun( 5458 v8::Local<v8::Value> result = CompileRun(
5468 "var array = new Array(400);" 5459 "var array = new Array(400);"
5469 "var tmp = new Array(1000);" 5460 "var tmp = new Array(1000);"
5470 "array[0] = 10;" 5461 "array[0] = 10;"
5471 "gc();" 5462 "gc();"
5472 "gc();" 5463 "gc();"
5473 "array.shift();" 5464 "array.shift();"
5474 "array;"); 5465 "array;");
5475 5466
5476 Handle<JSObject> o = 5467 Handle<JSObject> o = Handle<JSObject>::cast(
5477 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); 5468 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)));
5478 CHECK(heap->InOldSpace(o->elements())); 5469 CHECK(heap->InOldSpace(o->elements()));
5479 CHECK(heap->InOldSpace(*o)); 5470 CHECK(heap->InOldSpace(*o));
5480 Page* page = Page::FromAddress(o->elements()->address()); 5471 Page* page = Page::FromAddress(o->elements()->address());
5481 CHECK(page->parallel_sweeping_state().Value() <= 5472 CHECK(page->parallel_sweeping_state().Value() <=
5482 MemoryChunk::kSweepingFinalize || 5473 MemoryChunk::kSweepingFinalize ||
5483 Marking::IsBlack(Marking::MarkBitFrom(o->elements()))); 5474 Marking::IsBlack(Marking::MarkBitFrom(o->elements())));
5484 } 5475 }
5485 5476
5486 5477
5487 UNINITIALIZED_TEST(PromotionQueue) { 5478 UNINITIALIZED_TEST(PromotionQueue) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
5615 "for (var i = 0; i < 50; i++) {" 5606 "for (var i = 0; i < 50; i++) {"
5616 " var key = {'k' : i + 0.1};" 5607 " var key = {'k' : i + 0.1};"
5617 " weak_map.set(key, 1);" 5608 " weak_map.set(key, 1);"
5618 " future_keys.push({'x' : i + 0.2});" 5609 " future_keys.push({'x' : i + 0.2});"
5619 "}" 5610 "}"
5620 "weak_map"); 5611 "weak_map");
5621 if (marking->IsStopped()) { 5612 if (marking->IsStopped()) {
5622 CcTest::heap()->StartIncrementalMarking(); 5613 CcTest::heap()->StartIncrementalMarking();
5623 } 5614 }
5624 // Incrementally mark the backing store. 5615 // Incrementally mark the backing store.
5625 Handle<JSObject> obj = 5616 Handle<JSReceiver> obj =
5626 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); 5617 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result));
5627 Handle<JSWeakCollection> weak_map(reinterpret_cast<JSWeakCollection*>(*obj)); 5618 Handle<JSWeakCollection> weak_map(reinterpret_cast<JSWeakCollection*>(*obj));
5628 while (!Marking::IsBlack( 5619 while (!Marking::IsBlack(
5629 Marking::MarkBitFrom(HeapObject::cast(weak_map->table()))) && 5620 Marking::MarkBitFrom(HeapObject::cast(weak_map->table()))) &&
5630 !marking->IsStopped()) { 5621 !marking->IsStopped()) {
5631 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD); 5622 marking->Step(MB, IncrementalMarking::NO_GC_VIA_STACK_GUARD);
5632 } 5623 }
5633 // Stash the backing store in a handle. 5624 // Stash the backing store in a handle.
5634 Handle<Object> save(weak_map->table(), isolate); 5625 Handle<Object> save(weak_map->table(), isolate);
5635 // The following line will update the backing store. 5626 // The following line will update the backing store.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5675 CcTest::InitializeVM(); 5666 CcTest::InitializeVM();
5676 Isolate* isolate = CcTest::i_isolate(); 5667 Isolate* isolate = CcTest::i_isolate();
5677 Heap* heap = isolate->heap(); 5668 Heap* heap = isolate->heap();
5678 Factory* factory = isolate->factory(); 5669 Factory* factory = isolate->factory();
5679 HandleScope scope(isolate); 5670 HandleScope scope(isolate);
5680 CompileRun("function cls() { this.x = 10; }"); 5671 CompileRun("function cls() { this.x = 10; }");
5681 Handle<WeakCell> weak_prototype; 5672 Handle<WeakCell> weak_prototype;
5682 { 5673 {
5683 HandleScope inner_scope(isolate); 5674 HandleScope inner_scope(isolate);
5684 v8::Local<v8::Value> result = CompileRun("cls.prototype"); 5675 v8::Local<v8::Value> result = CompileRun("cls.prototype");
5685 Handle<JSObject> proto = 5676 Handle<JSReceiver> proto =
5686 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); 5677 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result));
5687 weak_prototype = inner_scope.CloseAndEscape(factory->NewWeakCell(proto)); 5678 weak_prototype = inner_scope.CloseAndEscape(factory->NewWeakCell(proto));
5688 } 5679 }
5689 CHECK(!weak_prototype->cleared()); 5680 CHECK(!weak_prototype->cleared());
5690 CompileRun( 5681 CompileRun(
5691 "var a = { };" 5682 "var a = { };"
5692 "a.x = new cls();" 5683 "a.x = new cls();"
5693 "cls.prototype = null;"); 5684 "cls.prototype = null;");
5694 for (int i = 0; i < 4; i++) { 5685 for (int i = 0; i < 4; i++) {
5695 heap->CollectAllGarbage(); 5686 heap->CollectAllGarbage();
5696 } 5687 }
5697 // The map of a.x keeps prototype alive 5688 // The map of a.x keeps prototype alive
5698 CHECK(!weak_prototype->cleared()); 5689 CHECK(!weak_prototype->cleared());
5699 // Change the map of a.x and make the previous map garbage collectable. 5690 // Change the map of a.x and make the previous map garbage collectable.
5700 CompileRun("a.x.__proto__ = {};"); 5691 CompileRun("a.x.__proto__ = {};");
5701 for (int i = 0; i < 4; i++) { 5692 for (int i = 0; i < 4; i++) {
5702 heap->CollectAllGarbage(); 5693 heap->CollectAllGarbage();
5703 } 5694 }
5704 CHECK(weak_prototype->cleared()); 5695 CHECK(weak_prototype->cleared());
5705 } 5696 }
5706 5697
5707 5698
5708 Handle<WeakCell> AddRetainedMap(Isolate* isolate, Heap* heap) { 5699 Handle<WeakCell> AddRetainedMap(Isolate* isolate, Heap* heap) {
5709 HandleScope inner_scope(isolate); 5700 HandleScope inner_scope(isolate);
5710 Handle<Map> map = Map::Create(isolate, 1); 5701 Handle<Map> map = Map::Create(isolate, 1);
5711 v8::Local<v8::Value> result = 5702 v8::Local<v8::Value> result =
5712 CompileRun("(function () { return {x : 10}; })();"); 5703 CompileRun("(function () { return {x : 10}; })();");
5713 Handle<JSObject> proto = 5704 Handle<JSReceiver> proto =
5714 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result)); 5705 v8::Utils::OpenHandle(*v8::Handle<v8::Object>::Cast(result));
5715 Map::SetPrototype(map, proto); 5706 Map::SetPrototype(map, proto);
5716 heap->AddRetainedMap(map); 5707 heap->AddRetainedMap(map);
5717 return inner_scope.CloseAndEscape(Map::WeakCellForMap(map)); 5708 return inner_scope.CloseAndEscape(Map::WeakCellForMap(map));
5718 } 5709 }
5719 5710
5720 5711
5721 void CheckMapRetainingFor(int n) { 5712 void CheckMapRetainingFor(int n) {
5722 FLAG_retain_maps_for_n_gc = n; 5713 FLAG_retain_maps_for_n_gc = n;
5723 Isolate* isolate = CcTest::i_isolate(); 5714 Isolate* isolate = CcTest::i_isolate();
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
6340 isolate->IncrementJsCallsFromApiCounter(); 6331 isolate->IncrementJsCallsFromApiCounter();
6341 isolate->IncrementJsCallsFromApiCounter(); 6332 isolate->IncrementJsCallsFromApiCounter();
6342 isolate->IncrementJsCallsFromApiCounter(); 6333 isolate->IncrementJsCallsFromApiCounter();
6343 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); 6334 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4);
6344 CheckDoubleEquals(2, calls_per_ms); 6335 CheckDoubleEquals(2, calls_per_ms);
6345 } 6336 }
6346 6337
6347 6338
6348 } // namespace internal 6339 } // namespace internal
6349 } // namespace v8 6340 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698