| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 void TestSeeds(Handle<JSFunction> fun, | 47 void TestSeeds(Handle<JSFunction> fun, |
| 48 Handle<Context> context, | 48 Handle<Context> context, |
| 49 uint32_t state0, | 49 uint32_t state0, |
| 50 uint32_t state1) { | 50 uint32_t state1) { |
| 51 bool has_pending_exception; | 51 bool has_pending_exception; |
| 52 Handle<JSObject> global(context->global_object()); | 52 Handle<JSObject> global(context->global_object()); |
| 53 Handle<ByteArray> seeds(context->random_seed()); | 53 Handle<ByteArray> seeds(context->random_seed()); |
| 54 | 54 |
| 55 SetSeeds(seeds, state0, state1); | 55 SetSeeds(seeds, state0, state1); |
| 56 Handle<Object> value = | 56 Handle<Object> value = Execution::Call( |
| 57 Execution::Call(fun, global, 0, NULL, &has_pending_exception); | 57 context->GetIsolate(), fun, global, 0, NULL, &has_pending_exception); |
| 58 CHECK(value->IsHeapNumber()); | 58 CHECK(value->IsHeapNumber()); |
| 59 CHECK(fun->IsOptimized()); | 59 CHECK(fun->IsOptimized()); |
| 60 double crankshaft_value = HeapNumber::cast(*value)->value(); | 60 double crankshaft_value = HeapNumber::cast(*value)->value(); |
| 61 | 61 |
| 62 SetSeeds(seeds, state0, state1); | 62 SetSeeds(seeds, state0, state1); |
| 63 V8::FillHeapNumberWithRandom(*value, *context); | 63 V8::FillHeapNumberWithRandom(*value, *context); |
| 64 double runtime_value = HeapNumber::cast(*value)->value(); | 64 double runtime_value = HeapNumber::cast(*value)->value(); |
| 65 CHECK_EQ(runtime_value, crankshaft_value); | 65 CHECK_EQ(runtime_value, crankshaft_value); |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 TEST(CrankshaftRandom) { | 69 TEST(CrankshaftRandom) { |
| 70 v8::V8::Initialize(); | 70 v8::V8::Initialize(); |
| 71 // Skip test if crankshaft is disabled. | 71 // Skip test if crankshaft is disabled. |
| 72 if (!Isolate::Current()->use_crankshaft()) return; | 72 if (!Isolate::Current()->use_crankshaft()) return; |
| 73 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 73 v8::Isolate* v8_isolate = v8::Isolate::GetCurrent(); |
| 74 v8::HandleScope scope(isolate); | 74 v8::HandleScope scope(v8_isolate); |
| 75 v8::Context::Scope context_scope(v8::Context::New(isolate)); | 75 v8::Context::Scope context_scope(v8::Context::New(v8_isolate)); |
| 76 | 76 |
| 77 Handle<Context> context(Isolate::Current()->context()); | 77 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 78 Handle<Context> context(isolate->context()); |
| 78 Handle<JSObject> global(context->global_object()); | 79 Handle<JSObject> global(context->global_object()); |
| 79 Handle<ByteArray> seeds(context->random_seed()); | 80 Handle<ByteArray> seeds(context->random_seed()); |
| 80 bool has_pending_exception; | 81 bool has_pending_exception; |
| 81 | 82 |
| 82 CompileRun("function f() { return Math.random(); }"); | 83 CompileRun("function f() { return Math.random(); }"); |
| 83 | 84 |
| 84 Object* string = Isolate::Current()->factory()->InternalizeOneByteString( | 85 Object* string = Isolate::Current()->factory()->InternalizeOneByteString( |
| 85 STATIC_ASCII_VECTOR("f"))->ToObjectChecked(); | 86 STATIC_ASCII_VECTOR("f"))->ToObjectChecked(); |
| 86 MaybeObject* fun_object = | 87 MaybeObject* fun_object = |
| 87 context->global_object()->GetProperty(String::cast(string)); | 88 context->global_object()->GetProperty(String::cast(string)); |
| 88 Handle<JSFunction> fun(JSFunction::cast(fun_object->ToObjectChecked())); | 89 Handle<JSFunction> fun(JSFunction::cast(fun_object->ToObjectChecked())); |
| 89 | 90 |
| 90 // Optimize function. | 91 // Optimize function. |
| 91 Execution::Call(fun, global, 0, NULL, &has_pending_exception); | 92 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); |
| 92 Execution::Call(fun, global, 0, NULL, &has_pending_exception); | 93 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); |
| 93 if (!fun->IsOptimized()) fun->MarkForLazyRecompilation(); | 94 if (!fun->IsOptimized()) fun->MarkForLazyRecompilation(); |
| 94 | 95 |
| 95 // Test with some random values. | 96 // Test with some random values. |
| 96 TestSeeds(fun, context, 0xC0C0AFFE, 0x31415926); | 97 TestSeeds(fun, context, 0xC0C0AFFE, 0x31415926); |
| 97 TestSeeds(fun, context, 0x01020304, 0xFFFFFFFF); | 98 TestSeeds(fun, context, 0x01020304, 0xFFFFFFFF); |
| 98 TestSeeds(fun, context, 0x00000001, 0x00000000); | 99 TestSeeds(fun, context, 0x00000001, 0x00000000); |
| 99 | 100 |
| 100 // Test that we bail out to runtime when seeds are uninitialized (zeros). | 101 // Test that we bail out to runtime when seeds are uninitialized (zeros). |
| 101 SetSeeds(seeds, 0, 0); | 102 SetSeeds(seeds, 0, 0); |
| 102 Handle<Object> value = | 103 Handle<Object> value = |
| 103 Execution::Call(fun, global, 0, NULL, &has_pending_exception); | 104 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); |
| 104 CHECK(value->IsHeapNumber()); | 105 CHECK(value->IsHeapNumber()); |
| 105 CHECK(fun->IsOptimized()); | 106 CHECK(fun->IsOptimized()); |
| 106 double crankshaft_value = HeapNumber::cast(*value)->value(); | 107 double crankshaft_value = HeapNumber::cast(*value)->value(); |
| 107 CHECK_NE(0.0, crankshaft_value); | 108 CHECK_NE(0.0, crankshaft_value); |
| 108 } | 109 } |
| OLD | NEW |