Revision: 24459
Author: [email protected]
Date: Wed Oct 8 09:23:33 2014 UTC
Log: The empty husk of a JSFunction is useful to us.
We hollow out the rotting core and with evil intent repurpose its dry
carcass to empower ourselves; with such a shell we can test.
[email protected]
BUG=
Review URL: https://codereview.chromium.org/637873002
https://code.google.com/p/v8/source/detail?r=24459
Modified:
/branches/bleeding_edge/test/cctest/compiler/function-tester.h
/branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/function-tester.h Thu Sep
18 09:02:36 2014 UTC
+++ /branches/bleeding_edge/test/cctest/compiler/function-tester.h Wed Oct
8 09:23:33 2014 UTC
@@ -9,6 +9,7 @@
#include "test/cctest/cctest.h"
#include "src/compiler.h"
+#include "src/compiler/linkage.h"
#include "src/compiler/pipeline.h"
#include "src/execution.h"
#include "src/full-codegen.h"
@@ -36,53 +37,17 @@
CompilationInfo::kTypingEnabled;
CHECK_EQ(0, flags_ & ~supported_flags);
}
+
+ explicit FunctionTester(Graph* graph)
+ : isolate(main_isolate()),
+ function(NewFunction("(function(a,b){})")),
+ flags_(0) {
+ CompileGraph(graph);
+ }
Isolate* isolate;
Handle<JSFunction> function;
- Handle<JSFunction> Compile(Handle<JSFunction> function) {
-#if V8_TURBOFAN_TARGET
- CompilationInfoWithZone info(function);
-
- CHECK(Parser::Parse(&info));
- info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
- if (flags_ & CompilationInfo::kContextSpecializing) {
- info.MarkAsContextSpecializing();
- }
- if (flags_ & CompilationInfo::kInliningEnabled) {
- info.MarkAsInliningEnabled();
- }
- if (flags_ & CompilationInfo::kTypingEnabled) {
- info.MarkAsTypingEnabled();
- }
- CHECK(Rewriter::Rewrite(&info));
- CHECK(Scope::Analyze(&info));
- CHECK(Compiler::EnsureDeoptimizationSupport(&info));
-
- Pipeline pipeline(&info);
- Handle<Code> code = pipeline.GenerateCode();
- if (FLAG_turbo_deoptimization) {
- info.context()->native_context()->AddOptimizedCode(*code);
- }
-
- CHECK(!code.is_null());
- function->ReplaceCode(*code);
-#elif USE_CRANKSHAFT
- Handle<Code> unoptimized = Handle<Code>(function->code());
- Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized,
-
Compiler::NOT_CONCURRENT);
- CHECK(!code.is_null());
-#if ENABLE_DISASSEMBLER
- if (FLAG_print_opt_code) {
- CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
- code->Disassemble("test code", tracing_scope.file());
- }
-#endif
- function->ReplaceCode(*code);
-#endif
- return function;
- }
-
MaybeHandle<Object> Call(Handle<Object> a, Handle<Object> b) {
Handle<Object> args[] = {a, b};
return Execution::Call(isolate, function, undefined(), 2, args, false);
@@ -182,9 +147,83 @@
Handle<Object> true_value() { return isolate->factory()->true_value(); }
Handle<Object> false_value() { return isolate->factory()->false_value();
}
+
+ Handle<JSFunction> Compile(Handle<JSFunction> function) {
+// TODO(titzer): make this method private.
+#if V8_TURBOFAN_TARGET
+ CompilationInfoWithZone info(function);
+
+ CHECK(Parser::Parse(&info));
+ info.SetOptimizing(BailoutId::None(), Handle<Code>(function->code()));
+ if (flags_ & CompilationInfo::kContextSpecializing) {
+ info.MarkAsContextSpecializing();
+ }
+ if (flags_ & CompilationInfo::kInliningEnabled) {
+ info.MarkAsInliningEnabled();
+ }
+ if (flags_ & CompilationInfo::kTypingEnabled) {
+ info.MarkAsTypingEnabled();
+ }
+ CHECK(Rewriter::Rewrite(&info));
+ CHECK(Scope::Analyze(&info));
+ CHECK(Compiler::EnsureDeoptimizationSupport(&info));
+
+ Pipeline pipeline(&info);
+ Handle<Code> code = pipeline.GenerateCode();
+ if (FLAG_turbo_deoptimization) {
+ info.context()->native_context()->AddOptimizedCode(*code);
+ }
+
+ CHECK(!code.is_null());
+ function->ReplaceCode(*code);
+#elif USE_CRANKSHAFT
+ Handle<Code> unoptimized = Handle<Code>(function->code());
+ Handle<Code> code = Compiler::GetOptimizedCode(function, unoptimized,
+
Compiler::NOT_CONCURRENT);
+ CHECK(!code.is_null());
+#if ENABLE_DISASSEMBLER
+ if (FLAG_print_opt_code) {
+ CodeTracer::Scope tracing_scope(isolate->GetCodeTracer());
+ code->Disassemble("test code", tracing_scope.file());
+ }
+#endif
+ function->ReplaceCode(*code);
+#endif
+ return function;
+ }
+
+ static Handle<JSFunction> ForMachineGraph(Graph* graph) {
+ JSFunction* p = NULL;
+ { // because of the implicit handle scope of FunctionTester.
+ FunctionTester f(graph);
+ p = *f.function;
+ }
+ return Handle<JSFunction>(p); // allocated in outer handle scope.
+ }
private:
uint32_t flags_;
+
+ // Compile the given machine graph instead of the source of the function
+ // and replace the JSFunction's code with the result.
+ Handle<JSFunction> CompileGraph(Graph* graph) {
+ CHECK(Pipeline::SupportedTarget());
+ CompilationInfoWithZone info(function);
+
+ CHECK(Parser::Parse(&info));
+ info.SetOptimizing(BailoutId::None(),
+ Handle<Code>(function->shared()->code()));
+ CHECK(Rewriter::Rewrite(&info));
+ CHECK(Scope::Analyze(&info));
+ CHECK(Compiler::EnsureDeoptimizationSupport(&info));
+
+ Pipeline pipeline(&info);
+ Linkage linkage(&info);
+ Handle<Code> code = pipeline.GenerateCodeForMachineGraph(&linkage,
graph);
+ CHECK(!code.is_null());
+ function->ReplaceCode(*code);
+ return function;
+ }
};
}
}
=======================================
--- /branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Wed Oct 1 11:08:37 2014 UTC
+++ /branches/bleeding_edge/test/cctest/compiler/test-changes-lowering.cc
Wed Oct 8 09:23:33 2014 UTC
@@ -19,6 +19,7 @@
#include "src/scopes.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/codegen-tester.h"
+#include "test/cctest/compiler/function-tester.h"
#include "test/cctest/compiler/graph-builder-tester.h"
#include "test/cctest/compiler/value-helper.h"
@@ -45,29 +46,10 @@
template <typename T>
T* CallWithPotentialGC() {
- // TODO(titzer): we need to wrap the code in a JSFunction and call it
via
- // Execution::Call() so that the GC knows about the frame, can walk it,
- // relocate the code object if necessary, etc.
- // This is pretty ugly and at the least should be moved up to helpers.
+ // TODO(titzer): we wrap the code in a JSFunction here to reuse the
+ // JSEntryStub; that could be done with a special prologue or other
stub.
if (function.is_null()) {
- function =
- v8::Utils::OpenHandle(*v8::Handle<v8::Function>::Cast(CompileRun(
- "(function() { 'use strict'; return 2.7123; })")));
- CompilationInfoWithZone info(function);
- CHECK(Parser::Parse(&info));
- info.SetOptimizing(BailoutId::None(),
Handle<Code>(function->code()));
- CHECK(Rewriter::Rewrite(&info));
- CHECK(Scope::Analyze(&info));
- CHECK_NE(NULL, info.scope());
- Handle<ScopeInfo> scope_info =
- ScopeInfo::Create(info.scope(), info.zone());
- info.shared_info()->set_scope_info(*scope_info);
- Pipeline pipeline(&info);
- Linkage linkage(&info);
- Handle<Code> code =
- pipeline.GenerateCodeForMachineGraph(&linkage, this->graph());
- CHECK(!code.is_null());
- function->ReplaceCode(*code);
+ function = FunctionTester::ForMachineGraph(this->graph());
}
Handle<Object>* args = NULL;
MaybeHandle<Object> result =
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.