diff options
Diffstat (limited to 'deps/v8/test/cctest/test-compiler.cc')
-rw-r--r-- | deps/v8/test/cctest/test-compiler.cc | 126 |
1 files changed, 64 insertions, 62 deletions
diff --git a/deps/v8/test/cctest/test-compiler.cc b/deps/v8/test/cctest/test-compiler.cc index cb559d8fe2..28867a89ef 100644 --- a/deps/v8/test/cctest/test-compiler.cc +++ b/deps/v8/test/cctest/test-compiler.cc @@ -28,17 +28,17 @@ #include <stdlib.h> #include <wchar.h> -#include "src/v8.h" +#include "src/init/v8.h" -#include "src/api-inl.h" -#include "src/compilation-cache.h" -#include "src/compiler.h" -#include "src/disasm.h" +#include "src/api/api-inl.h" +#include "src/codegen/compilation-cache.h" +#include "src/codegen/compiler.h" +#include "src/diagnostics/disasm.h" #include "src/heap/factory.h" #include "src/heap/spaces.h" #include "src/interpreter/interpreter.h" -#include "src/objects-inl.h" #include "src/objects/allocation-site-inl.h" +#include "src/objects/objects-inl.h" #include "test/cctest/cctest.h" namespace v8 { @@ -55,7 +55,7 @@ static void SetGlobalProperty(const char* name, Object value) { Handle<Object> object(value, isolate); Handle<String> internalized_name = isolate->factory()->InternalizeUtf8String(name); - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Runtime::SetObjectProperty(isolate, global, internalized_name, object, StoreOrigin::kMaybeKeyed, Just(kDontThrow)) .Check(); @@ -82,10 +82,10 @@ static double Inc(Isolate* isolate, int x) { EmbeddedVector<char, 512> buffer; SNPrintF(buffer, source, x); - Handle<JSFunction> fun = Compile(buffer.start()); + Handle<JSFunction> fun = Compile(buffer.begin()); if (fun.is_null()) return -1; - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Execution::Call(isolate, fun, global, 0, nullptr).Check(); return GetGlobalProperty("result")->Number(); } @@ -104,7 +104,7 @@ static double Add(Isolate* isolate, int x, int y) { SetGlobalProperty("x", Smi::FromInt(x)); SetGlobalProperty("y", Smi::FromInt(y)); - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Execution::Call(isolate, fun, global, 0, nullptr).Check(); return GetGlobalProperty("result")->Number(); } @@ -122,7 +122,7 @@ static double Abs(Isolate* isolate, int x) { if (fun.is_null()) return -1; SetGlobalProperty("x", Smi::FromInt(x)); - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Execution::Call(isolate, fun, global, 0, nullptr).Check(); return GetGlobalProperty("result")->Number(); } @@ -141,7 +141,7 @@ static double Sum(Isolate* isolate, int n) { if (fun.is_null()) return -1; SetGlobalProperty("n", Smi::FromInt(n)); - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Execution::Call(isolate, fun, global, 0, nullptr).Check(); return GetGlobalProperty("result")->Number(); } @@ -161,7 +161,7 @@ TEST(Print) { const char* source = "for (n = 0; n < 100; ++n) print(n, 1, 2);"; Handle<JSFunction> fun = Compile(source); if (fun.is_null()) return; - Handle<JSObject> global(CcTest::i_isolate()->context()->global_object(), + Handle<JSObject> global(CcTest::i_isolate()->context().global_object(), fun->GetIsolate()); Execution::Call(CcTest::i_isolate(), fun, global, 0, nullptr).Check(); } @@ -193,7 +193,7 @@ TEST(Stuff) { Handle<JSFunction> fun = Compile(source); CHECK(!fun.is_null()); - Handle<JSObject> global(CcTest::i_isolate()->context()->global_object(), + Handle<JSObject> global(CcTest::i_isolate()->context().global_object(), fun->GetIsolate()); Execution::Call(CcTest::i_isolate(), fun, global, 0, nullptr).Check(); CHECK_EQ(511.0, GetGlobalProperty("r")->Number()); @@ -208,9 +208,9 @@ TEST(UncaughtThrow) { Handle<JSFunction> fun = Compile(source); CHECK(!fun.is_null()); Isolate* isolate = fun->GetIsolate(); - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); CHECK(Execution::Call(isolate, fun, global, 0, nullptr).is_null()); - CHECK_EQ(42.0, isolate->pending_exception()->Number()); + CHECK_EQ(42.0, isolate->pending_exception().Number()); } @@ -234,7 +234,7 @@ TEST(C2JSFrames) { Isolate* isolate = fun0->GetIsolate(); // Run the generated code to populate the global object with 'foo'. - Handle<JSObject> global(isolate->context()->global_object(), isolate); + Handle<JSObject> global(isolate->context().global_object(), isolate); Execution::Call(isolate, fun0, global, 0, nullptr).Check(); Handle<Object> fun1 = @@ -243,7 +243,7 @@ TEST(C2JSFrames) { CHECK(fun1->IsJSFunction()); Handle<Object> argv[] = { - isolate->factory()->InternalizeOneByteString(StaticCharVector("hello"))}; + isolate->factory()->InternalizeString(StaticCharVector("hello"))}; Execution::Call(isolate, Handle<JSFunction>::cast(fun1), global, @@ -276,14 +276,14 @@ TEST(GetScriptLineNumber) { const int max_rows = 1000; const int buffer_size = max_rows + sizeof(function_f); ScopedVector<char> buffer(buffer_size); - memset(buffer.start(), '\n', buffer_size - 1); + memset(buffer.begin(), '\n', buffer_size - 1); buffer[buffer_size - 1] = '\0'; for (int i = 0; i < max_rows; ++i) { if (i > 0) buffer[i - 1] = '\n'; MemCopy(&buffer[i], function_f, sizeof(function_f) - 1); - v8::Local<v8::String> script_body = v8_str(buffer.start()); + v8::Local<v8::String> script_body = v8_str(buffer.begin()); v8::Script::Compile(context.local(), script_body, &origin) .ToLocalChecked() ->Run(context.local()) @@ -304,9 +304,11 @@ TEST(FeedbackVectorPreservedAcrossRecompiles) { v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); // Make sure function f has a call that uses a type feedback slot. - CompileRun("function fun() {};" - "fun1 = fun;" - "function f(a) { a(); } f(fun1);"); + CompileRun( + "function fun() {};" + "fun1 = fun;" + "%PrepareFunctionForOptimization(f);" + "function f(a) { a(); } f(fun1);"); Handle<JSFunction> f = Handle<JSFunction>::cast( v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( @@ -320,7 +322,7 @@ TEST(FeedbackVectorPreservedAcrossRecompiles) { { HeapObject heap_object; CHECK(object->GetHeapObjectIfWeak(&heap_object)); - CHECK(heap_object->IsJSFunction()); + CHECK(heap_object.IsJSFunction()); } CompileRun("%OptimizeFunctionOnNextCall(f); f(fun1);"); @@ -328,11 +330,11 @@ TEST(FeedbackVectorPreservedAcrossRecompiles) { // Verify that the feedback is still "gathered" despite a recompilation // of the full code. CHECK(f->IsOptimized()); - object = f->feedback_vector()->Get(slot_for_a); + object = f->feedback_vector().Get(slot_for_a); { HeapObject heap_object; CHECK(object->GetHeapObjectIfWeak(&heap_object)); - CHECK(heap_object->IsJSFunction()); + CHECK(heap_object.IsJSFunction()); } } @@ -364,13 +366,13 @@ TEST(FeedbackVectorUnaffectedByScopeChanges) { // If we are compiling lazily then it should not be compiled, and so no // feedback vector allocated yet. - CHECK(!f->shared()->is_compiled()); + CHECK(!f->shared().is_compiled()); CompileRun("morphing_call();"); - // Now a feedback vector is allocated. - CHECK(f->shared()->is_compiled()); - CHECK(!f->feedback_vector()->is_empty()); + // Now a feedback vector / closure feedback cell array is allocated. + CHECK(f->shared().is_compiled()); + CHECK(f->has_feedback_vector() || f->has_closure_feedback_cell_array()); } // Test that optimized code for different closures is actually shared. @@ -391,6 +393,7 @@ TEST(OptimizedCodeSharing1) { "var closure0 = MakeClosure();" "var closure1 = MakeClosure();" // We only share optimized code // if there are at least two closures. + "%PrepareFunctionForOptimization(closure0);" "%DebugPrint(closure0());" "%OptimizeFunctionOnNextCall(closure0);" "%DebugPrint(closure0());" @@ -647,16 +650,11 @@ TEST(CompileFunctionInContextScriptOrigin) { v8::Integer::New(CcTest::isolate(), 22), v8::Integer::New(CcTest::isolate(), 41)); v8::ScriptCompiler::Source script_source(v8_str("throw new Error()"), origin); - Local<ScriptOrModule> script; v8::Local<v8::Function> fun = - v8::ScriptCompiler::CompileFunctionInContext( - env.local(), &script_source, 0, nullptr, 0, nullptr, - v8::ScriptCompiler::CompileOptions::kNoCompileOptions, - v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason, &script) + v8::ScriptCompiler::CompileFunctionInContext(env.local(), &script_source, + 0, nullptr, 0, nullptr) .ToLocalChecked(); CHECK(!fun.IsEmpty()); - CHECK(!script.IsEmpty()); - CHECK(script->GetResourceName()->StrictEquals(v8_str("test"))); v8::TryCatch try_catch(CcTest::isolate()); CcTest::isolate()->SetCaptureStackTraceForUncaughtExceptions(true); CHECK(fun->Call(env.local(), env->Global(), 0, nullptr).IsEmpty()); @@ -672,17 +670,16 @@ TEST(CompileFunctionInContextScriptOrigin) { } void TestCompileFunctionInContextToStringImpl() { -#define CHECK_NOT_CAUGHT(__local_context__, try_catch, __op__) \ - do { \ - const char* op = (__op__); \ - v8::Local<v8::Context> context = (__local_context__); \ - if (try_catch.HasCaught()) { \ - v8::String::Utf8Value error( \ - CcTest::isolate(), \ - try_catch.Exception()->ToString(context).ToLocalChecked()); \ - V8_Fatal(__FILE__, __LINE__, \ - "Unexpected exception thrown during %s:\n\t%s\n", op, *error); \ - } \ +#define CHECK_NOT_CAUGHT(__local_context__, try_catch, __op__) \ + do { \ + const char* op = (__op__); \ + v8::Local<v8::Context> context = (__local_context__); \ + if (try_catch.HasCaught()) { \ + v8::String::Utf8Value error( \ + CcTest::isolate(), \ + try_catch.Exception()->ToString(context).ToLocalChecked()); \ + FATAL("Unexpected exception thrown during %s:\n\t%s\n", op, *error); \ + } \ } while (false) { // NOLINT @@ -786,16 +783,18 @@ TEST(InvocationCount) { CompileRun( "function bar() {};" + "%EnsureFeedbackVectorForFunction(bar);" "function foo() { return bar(); };" + "%EnsureFeedbackVectorForFunction(foo);" "foo();"); Handle<JSFunction> foo = Handle<JSFunction>::cast(GetGlobalProperty("foo")); - CHECK_EQ(1, foo->feedback_vector()->invocation_count()); + CHECK_EQ(1, foo->feedback_vector().invocation_count()); CompileRun("foo()"); - CHECK_EQ(2, foo->feedback_vector()->invocation_count()); + CHECK_EQ(2, foo->feedback_vector().invocation_count()); CompileRun("bar()"); - CHECK_EQ(2, foo->feedback_vector()->invocation_count()); + CHECK_EQ(2, foo->feedback_vector().invocation_count()); CompileRun("foo(); foo()"); - CHECK_EQ(4, foo->feedback_vector()->invocation_count()); + CHECK_EQ(4, foo->feedback_vector().invocation_count()); } TEST(SafeToSkipArgumentsAdaptor) { @@ -809,17 +808,17 @@ TEST(SafeToSkipArgumentsAdaptor) { "function e() { \"use strict\"; return eval(\"\"); }; e();" "function f(x, y) { \"use strict\"; return x + y; }; f(1, 2);"); Handle<JSFunction> a = Handle<JSFunction>::cast(GetGlobalProperty("a")); - CHECK(a->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(a->shared().is_safe_to_skip_arguments_adaptor()); Handle<JSFunction> b = Handle<JSFunction>::cast(GetGlobalProperty("b")); - CHECK(!b->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(!b->shared().is_safe_to_skip_arguments_adaptor()); Handle<JSFunction> c = Handle<JSFunction>::cast(GetGlobalProperty("c")); - CHECK(!c->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(!c->shared().is_safe_to_skip_arguments_adaptor()); Handle<JSFunction> d = Handle<JSFunction>::cast(GetGlobalProperty("d")); - CHECK(!d->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(!d->shared().is_safe_to_skip_arguments_adaptor()); Handle<JSFunction> e = Handle<JSFunction>::cast(GetGlobalProperty("e")); - CHECK(!e->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(!e->shared().is_safe_to_skip_arguments_adaptor()); Handle<JSFunction> f = Handle<JSFunction>::cast(GetGlobalProperty("f")); - CHECK(f->shared()->is_safe_to_skip_arguments_adaptor()); + CHECK(f->shared().is_safe_to_skip_arguments_adaptor()); } TEST(ShallowEagerCompilation) { @@ -945,10 +944,10 @@ TEST(DeepEagerCompilationPeakMemory) { // TODO(mslekova): Remove the duplication with test-heap.cc static int AllocationSitesCount(Heap* heap) { int count = 0; - for (Object site = heap->allocation_sites_list(); site->IsAllocationSite();) { + for (Object site = heap->allocation_sites_list(); site.IsAllocationSite();) { AllocationSite cur = AllocationSite::cast(site); - CHECK(cur->HasWeakNext()); - site = cur->weak_next(); + CHECK(cur.HasWeakNext()); + site = cur.weak_next(); count++; } return count; @@ -1013,6 +1012,7 @@ TEST(DecideToPretenureDuringCompilation) { " foo(shouldKeep);" " }" "}" + "%PrepareFunctionForOptimization(bar);" "bar();"); // This number should be >= kPretenureRatio * 10000, @@ -1036,7 +1036,9 @@ TEST(DecideToPretenureDuringCompilation) { // Check `bar` can get optimized again, meaning the compiler state is // recoverable from this point. - CompileRun("%OptimizeFunctionOnNextCall(bar);"); + CompileRun( + "%PrepareFunctionForOptimization(bar);" + "%OptimizeFunctionOnNextCall(bar);"); CompileRun("bar();"); Handle<Object> foo_obj = |