OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) { | 55 static bool HasArrayBufferInWeakList(Heap* heap, JSArrayBuffer* ab) { |
56 for (Object* o = heap->array_buffers_list(); | 56 for (Object* o = heap->array_buffers_list(); |
57 !o->IsUndefined(); | 57 !o->IsUndefined(); |
58 o = JSArrayBuffer::cast(o)->weak_next()) { | 58 o = JSArrayBuffer::cast(o)->weak_next()) { |
59 if (ab == o) return true; | 59 if (ab == o) return true; |
60 } | 60 } |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 static int CountViewsInNewSpaceList(Heap* heap, JSArrayBuffer* array_buffer) { | 65 #if 0 |
Hannes Payer (out of office)
2015/04/22 07:45:53
Do the tests still make sense? If not, just remove
jochen (gone - plz use gerrit)
2015/04/22 08:21:42
we'd need a way to iterate the entire heap (or at
| |
66 int count = 0; | |
67 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined();) { | |
68 JSArrayBufferView* view = JSArrayBufferView::cast(o); | |
69 if (array_buffer == view->buffer()) { | |
70 count++; | |
71 } | |
72 o = view->weak_next(); | |
73 } | |
74 return count; | |
75 } | |
76 | |
77 | |
78 static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) { | 66 static int CountViews(Heap* heap, JSArrayBuffer* array_buffer) { |
79 int count = 0; | 67 int count = 0; |
80 for (Object* o = array_buffer->weak_first_view(); | 68 for (Object* o = array_buffer->weak_first_view(); |
81 !o->IsUndefined(); | 69 !o->IsUndefined(); |
82 o = JSArrayBufferView::cast(o)->weak_next()) { | 70 o = JSArrayBufferView::cast(o)->weak_next()) { |
83 count++; | 71 count++; |
84 } | 72 } |
85 | 73 |
86 return count + CountViewsInNewSpaceList(heap, array_buffer); | 74 return count; |
87 } | 75 } |
88 | 76 |
89 | 77 |
90 static bool HasViewInNewSpaceList(Heap* heap, JSArrayBufferView* ta) { | |
91 for (Object* o = heap->new_array_buffer_views_list(); !o->IsUndefined(); | |
92 o = JSArrayBufferView::cast(o)->weak_next()) { | |
93 if (ta == o) return true; | |
94 } | |
95 return false; | |
96 } | |
97 | |
98 | |
99 static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer, | 78 static bool HasViewInWeakList(Heap* heap, JSArrayBuffer* array_buffer, |
100 JSArrayBufferView* ta) { | 79 JSArrayBufferView* ta) { |
101 for (Object* o = array_buffer->weak_first_view(); | 80 for (Object* o = array_buffer->weak_first_view(); |
102 !o->IsUndefined(); | 81 !o->IsUndefined(); |
103 o = JSArrayBufferView::cast(o)->weak_next()) { | 82 o = JSArrayBufferView::cast(o)->weak_next()) { |
104 if (ta == o) return true; | 83 if (ta == o) return true; |
105 } | 84 } |
106 return HasViewInNewSpaceList(heap, ta); | 85 return false; |
107 } | 86 } |
108 | 87 |
109 | 88 |
110 TEST(WeakArrayBuffersFromApi) { | 89 TEST(WeakArrayBuffersFromApi) { |
111 v8::V8::Initialize(); | 90 v8::V8::Initialize(); |
112 LocalContext context; | 91 LocalContext context; |
113 Isolate* isolate = GetIsolateFrom(&context); | 92 Isolate* isolate = GetIsolateFrom(&context); |
114 | 93 |
115 int start = CountArrayBuffersInWeakList(isolate->heap()); | 94 int start = CountArrayBuffersInWeakList(isolate->heap()); |
116 { | 95 { |
(...skipping 17 matching lines...) Expand all Loading... | |
134 HandleScope scope2(isolate); | 113 HandleScope scope2(isolate); |
135 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); | 114 Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1); |
136 | 115 |
137 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); | 116 CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1)); |
138 } | 117 } |
139 } | 118 } |
140 | 119 |
141 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 120 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
142 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); | 121 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); |
143 } | 122 } |
123 #endif | |
144 | 124 |
145 | 125 |
146 TEST(WeakArrayBuffersFromScript) { | 126 TEST(WeakArrayBuffersFromScript) { |
147 v8::V8::Initialize(); | 127 v8::V8::Initialize(); |
148 LocalContext context; | 128 LocalContext context; |
149 Isolate* isolate = GetIsolateFrom(&context); | 129 Isolate* isolate = GetIsolateFrom(&context); |
150 int start = CountArrayBuffersInWeakList(isolate->heap()); | 130 int start = CountArrayBuffersInWeakList(isolate->heap()); |
151 | 131 |
152 for (int i = 1; i <= 3; i++) { | 132 for (int i = 1; i <= 3; i++) { |
153 // Create 3 array buffers, make i-th of them garbage, | 133 // Create 3 array buffers, make i-th of them garbage, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); | 179 CompileRun("ab1 = null; ab2 = null; ab3 = null;"); |
200 } | 180 } |
201 | 181 |
202 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 182 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
203 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); | 183 CHECK_EQ(start, CountArrayBuffersInWeakList(isolate->heap())); |
204 } | 184 } |
205 } | 185 } |
206 | 186 |
207 template <typename View> | 187 template <typename View> |
208 void TestViewFromApi() { | 188 void TestViewFromApi() { |
189 #if 0 | |
209 v8::V8::Initialize(); | 190 v8::V8::Initialize(); |
210 LocalContext context; | 191 LocalContext context; |
211 Isolate* isolate = GetIsolateFrom(&context); | 192 Isolate* isolate = GetIsolateFrom(&context); |
212 | 193 |
213 v8::HandleScope s1(context->GetIsolate()); | 194 v8::HandleScope s1(context->GetIsolate()); |
214 v8::Handle<v8::ArrayBuffer> ab = | 195 v8::Handle<v8::ArrayBuffer> ab = |
215 v8::ArrayBuffer::New(context->GetIsolate(), 2048); | 196 v8::ArrayBuffer::New(context->GetIsolate(), 2048); |
216 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 197 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
217 { | 198 { |
218 v8::HandleScope s2(context->GetIsolate()); | 199 v8::HandleScope s2(context->GetIsolate()); |
219 v8::Handle<View> ta1 = View::New(ab, 0, 256); | 200 v8::Handle<View> ta1 = View::New(ab, 0, 256); |
220 { | 201 { |
221 v8::HandleScope s3(context->GetIsolate()); | 202 v8::HandleScope s3(context->GetIsolate()); |
222 v8::Handle<View> ta2 = View::New(ab, 0, 128); | 203 v8::Handle<View> ta2 = View::New(ab, 0, 128); |
223 | 204 |
224 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); | 205 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
225 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); | 206 Handle<JSArrayBufferView> ita2 = v8::Utils::OpenHandle(*ta2); |
226 CHECK_EQ(2, CountViews(isolate->heap(), *iab)); | 207 CHECK_EQ(2, CountViews(isolate->heap(), *iab)); |
227 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); | 208 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); |
228 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2)); | 209 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita2)); |
229 } | 210 } |
230 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 211 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
231 CHECK_EQ(1, CountViews(isolate->heap(), *iab)); | 212 CHECK_EQ(1, CountViews(isolate->heap(), *iab)); |
232 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); | 213 Handle<JSArrayBufferView> ita1 = v8::Utils::OpenHandle(*ta1); |
233 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); | 214 CHECK(HasViewInWeakList(isolate->heap(), *iab, *ita1)); |
234 } | 215 } |
235 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); | 216 isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask); |
236 | 217 |
237 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); | 218 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); |
219 #endif | |
238 } | 220 } |
239 | 221 |
240 | 222 |
241 TEST(Uint8ArrayFromApi) { | 223 TEST(Uint8ArrayFromApi) { |
242 TestViewFromApi<v8::Uint8Array>(); | 224 TestViewFromApi<v8::Uint8Array>(); |
243 } | 225 } |
244 | 226 |
245 | 227 |
246 TEST(Int8ArrayFromApi) { | 228 TEST(Int8ArrayFromApi) { |
247 TestViewFromApi<v8::Int8Array>(); | 229 TestViewFromApi<v8::Int8Array>(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 TestViewFromApi<v8::Uint8ClampedArray>(); | 264 TestViewFromApi<v8::Uint8ClampedArray>(); |
283 } | 265 } |
284 | 266 |
285 | 267 |
286 TEST(DataViewFromApi) { | 268 TEST(DataViewFromApi) { |
287 TestViewFromApi<v8::DataView>(); | 269 TestViewFromApi<v8::DataView>(); |
288 } | 270 } |
289 | 271 |
290 template <typename TypedArray> | 272 template <typename TypedArray> |
291 static void TestTypedArrayFromScript(const char* constructor) { | 273 static void TestTypedArrayFromScript(const char* constructor) { |
274 #if 0 | |
292 v8::V8::Initialize(); | 275 v8::V8::Initialize(); |
293 LocalContext context; | 276 LocalContext context; |
294 Isolate* isolate = GetIsolateFrom(&context); | 277 Isolate* isolate = GetIsolateFrom(&context); |
295 v8::HandleScope scope(context->GetIsolate()); | 278 v8::HandleScope scope(context->GetIsolate()); |
296 int start = CountArrayBuffersInWeakList(isolate->heap()); | 279 int start = CountArrayBuffersInWeakList(isolate->heap()); |
297 CompileRun("var ab = new ArrayBuffer(2048);"); | 280 CompileRun("var ab = new ArrayBuffer(2048);"); |
298 for (int i = 1; i <= 3; i++) { | 281 for (int i = 1; i <= 3; i++) { |
299 // Create 3 typed arrays, make i-th of them garbage, | 282 // Create 3 typed arrays, make i-th of them garbage, |
300 // validate correct state of typed array weak list. | 283 // validate correct state of typed array weak list. |
301 v8::HandleScope s0(context->GetIsolate()); | 284 v8::HandleScope s0(context->GetIsolate()); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
359 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); | 342 CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start); |
360 | 343 |
361 { | 344 { |
362 v8::HandleScope s3(context->GetIsolate()); | 345 v8::HandleScope s3(context->GetIsolate()); |
363 v8::Handle<v8::ArrayBuffer> ab = | 346 v8::Handle<v8::ArrayBuffer> ab = |
364 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 347 v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
365 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); | 348 Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab); |
366 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); | 349 CHECK_EQ(0, CountViews(isolate->heap(), *iab)); |
367 } | 350 } |
368 } | 351 } |
352 #endif | |
369 } | 353 } |
370 | 354 |
371 | 355 |
372 TEST(Uint8ArrayFromScript) { | 356 TEST(Uint8ArrayFromScript) { |
373 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); | 357 TestTypedArrayFromScript<v8::Uint8Array>("Uint8Array"); |
374 } | 358 } |
375 | 359 |
376 | 360 |
377 TEST(Int8ArrayFromScript) { | 361 TEST(Int8ArrayFromScript) { |
378 TestTypedArrayFromScript<v8::Int8Array>("Int8Array"); | 362 TestTypedArrayFromScript<v8::Int8Array>("Int8Array"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 | 394 |
411 | 395 |
412 TEST(Uint8ClampedArrayFromScript) { | 396 TEST(Uint8ClampedArrayFromScript) { |
413 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); | 397 TestTypedArrayFromScript<v8::Uint8ClampedArray>("Uint8ClampedArray"); |
414 } | 398 } |
415 | 399 |
416 | 400 |
417 TEST(DataViewFromScript) { | 401 TEST(DataViewFromScript) { |
418 TestTypedArrayFromScript<v8::DataView>("DataView"); | 402 TestTypedArrayFromScript<v8::DataView>("DataView"); |
419 } | 403 } |
OLD | NEW |