37 using namespace v8::internal;
39 static MaybeObject* GetGlobalProperty(
const char*
name) {
47 static void SetGlobalProperty(
const char* name,
Object* value) {
76 static double Inc(
Isolate* isolate,
int x) {
77 const char* source =
"result = %d + 1;";
84 bool has_pending_exception;
87 CHECK(!has_pending_exception);
88 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
99 static double Add(
Isolate* isolate,
int x,
int y) {
105 bool has_pending_exception;
108 CHECK(!has_pending_exception);
109 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
125 bool has_pending_exception;
128 CHECK(!has_pending_exception);
129 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
140 static double Sum(
Isolate* isolate,
int n) {
142 Compile(
"s = 0; while (n > 0) { s += n; n -= 1; }; result = s;");
146 bool has_pending_exception;
149 CHECK(!has_pending_exception);
150 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
165 const char* source =
"for (n = 0; n < 100; ++n) print(n, 1, 2);";
168 bool has_pending_exception;
172 CHECK(!has_pending_exception);
184 "if (a == a) r+=1;\n"
185 "if (a != new Object()) r+=2;\n"
187 "if (a.x == 42) r+=4;\n"
188 "function foo() { var x = 87; return x; }\n"
189 "if (foo() == 87) r+=8;\n"
190 "function bar() { var x; x = 99; return x; }\n"
191 "if (bar() == 99) r+=16;\n"
192 "function baz() { var x = 1, y, z = 2; y = 3; return x + y + z; }\n"
193 "if (baz() == 6) r+=32;\n"
194 "function Cons0() { this.x = 42; this.y = 87; }\n"
195 "if (new Cons0().x == 42) r+=64;\n"
196 "if (new Cons0().y == 87) r+=128;\n"
197 "function Cons2(x, y) { this.sum = x + y; }\n"
198 "if (new Cons2(3,4).sum == 7) r+=256;";
202 bool has_pending_exception;
206 CHECK(!has_pending_exception);
207 CHECK_EQ(511.0, GetGlobalProperty(
"r")->ToObjectChecked()->Number());
215 const char* source =
"throw 42;";
218 bool has_pending_exception;
219 Isolate* isolate = fun->GetIsolate();
222 CHECK(has_pending_exception);
234 FLAG_expose_gc =
true;
240 const char* source =
"function foo(a) { gc(), print(a); }";
244 Isolate* isolate = fun0->GetIsolate();
247 bool has_pending_exception;
250 isolate, fun0, global, 0,
NULL, &has_pending_exception);
251 CHECK(!has_pending_exception);
253 Object* foo_string = isolate->factory()->InternalizeOneByteString(
255 MaybeObject* fun1_object = isolate->context()->global_object()->
258 CHECK(fun1->IsJSFunction());
260 Handle<Object> argv[] = { isolate->factory()->InternalizeOneByteString(
267 &has_pending_exception);
268 CHECK(!has_pending_exception);
293 const char function_f[] =
"function f() {}";
294 const int max_rows = 1000;
295 const int buffer_size = max_rows +
sizeof(function_f);
297 memset(buffer.start(),
'\n', buffer_size - 1);
298 buffer[buffer_size - 1] =
'\0';
300 for (
int i = 0; i < max_rows; ++i) {
302 buffer[i - 1] =
'\n';
303 OS::MemCopy(&buffer[i], function_f,
sizeof(function_f) - 1);
320 if (!FLAG_cache_optimized_code)
return;
321 FLAG_stress_compaction =
false;
322 FLAG_allow_natives_syntax =
true;
325 for (
int i = 0; i < 10; i++) {
329 CompileRun(
"function MakeClosure() {"
330 " return function() { return x; };"
332 "var closure0 = MakeClosure();"
333 "%DebugPrint(closure0());"
334 "%OptimizeFunctionOnNextCall(closure0);"
335 "%DebugPrint(closure0());"
336 "var closure1 = MakeClosure();"
337 "var closure2 = MakeClosure();");
342 CHECK(fun1->IsOptimized()
344 CHECK(fun2->IsOptimized()
346 CHECK_EQ(fun1->code(), fun2->code());
351 #ifdef ENABLE_DISASSEMBLER
353 const char* property_name) {
365 if (f->code()->kind() == Code::FUNCTION) {
366 Address pc = f->code()->instruction_start();
368 Min(f->code()->instruction_size(),
369 static_cast<int>(f->code()->back_edge_table_offset()));
370 Address end = pc + decode_size;
375 OS::SNPrintF(smi_hex_buffer,
"0x%lx", reinterpret_cast<intptr_t>(smi));
377 int num_const = d.ConstantPoolSizeAt(pc);
378 if (num_const >= 0) {
381 pc += d.InstructionDecode(decode_buffer, pc);
389 TEST(SplitConstantsInFullCompiler) {
393 CompileRun(
"function f() { a = 12345678 }; f();");
394 CheckCodeForUnsafeLiteral(GetJSFunction(context->
Global(),
"f"));
395 CompileRun(
"function f(x) { a = 12345678 + x}; f(1);");
396 CheckCodeForUnsafeLiteral(GetJSFunction(context->
Global(),
"f"));
397 CompileRun(
"function f(x) { var arguments = 1; x += 12345678}; f(1);");
398 CheckCodeForUnsafeLiteral(GetJSFunction(context->
Global(),
"f"));
399 CompileRun(
"function f(x) { var arguments = 1; x = 12345678}; f(1);");
400 CheckCodeForUnsafeLiteral(GetJSFunction(context->
Global(),
"f"));
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
#define CHECK_EQ(expected, value)
Handle< JSFunction > NewFunctionFromSharedFunctionInfo(Handle< SharedFunctionInfo > function_info, Handle< Context > context, PretenureFlag pretenure=TENURED)
static Handle< SharedFunctionInfo > CompileScript(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, bool is_shared_cross_origin, Handle< Context > context, v8::Extension *extension, ScriptDataImpl **cached_data, CachedDataMode cached_data_mode, NativesFlag is_natives_code)
MaybeObject * pending_exception()
static String * cast(Object *obj)
Local< Value > Get(Handle< Value > key)
static Smi * FromInt(int value)
Handle< Script > NewScript(Handle< String > source)
static Local< Integer > New(Isolate *isolate, int32_t value)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
static v8::Local< v8::Context > NewContext(CcTestExtensionFlags extensions, v8::Isolate *isolate=CcTest::isolate())
GlobalObject * global_object()
Handle< String > NewStringFromUtf8(Vector< const char > str, PretenureFlag pretenure=NOT_TENURED)
static void MemCopy(void *dest, const void *src, size_t size)
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *script_data=NULL)
static i::Isolate * i_isolate()
#define STATIC_ASCII_VECTOR(x)
static v8::internal::Handle< To > OpenHandle(v8::Local< From > handle)
static V8_INLINE Local< T > Cast(Local< S > that)
Vector< const char > CStrVector(const char *data)
MUST_USE_RESULT MaybeObject * GetProperty(Name *key)
bool use_crankshaft() const
static int SNPrintF(Vector< char > str, const char *format,...)
int GetScriptLineNumber(Handle< Script > script, int code_pos)
static void InitializeVM()
static Handle< Object > Call(Isolate *isolate, Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *pending_exception, bool convert_receiver=false)
Handle< String > InternalizeUtf8String(Vector< const char > str)
int GetScriptLineNumber() const
void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
static Handle< Object > SetObjectProperty(Isolate *isolate, Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attr, StrictMode strict_mode)
Handle< Context > native_context()
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
static v8::Isolate * isolate()
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)