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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // o esp: stack pointer (pointing to return address) | 112 // o esp: stack pointer (pointing to return address) |
113 // | 113 // |
114 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 114 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
115 // frames-ia32.h for its layout. | 115 // frames-ia32.h for its layout. |
116 void FullCodeGenerator::Generate(CompilationInfo* info) { | 116 void FullCodeGenerator::Generate(CompilationInfo* info) { |
117 ASSERT(info_ == NULL); | 117 ASSERT(info_ == NULL); |
118 info_ = info; | 118 info_ = info; |
119 scope_ = info->scope(); | 119 scope_ = info->scope(); |
120 handler_table_ = | 120 handler_table_ = |
121 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 121 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
| 122 profiling_counter_ = isolate()->factory()->NewJSGlobalPropertyCell( |
| 123 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget))); |
122 SetFunctionPosition(function()); | 124 SetFunctionPosition(function()); |
123 Comment cmnt(masm_, "[ function compiled by full code generator"); | 125 Comment cmnt(masm_, "[ function compiled by full code generator"); |
124 | 126 |
125 #ifdef DEBUG | 127 #ifdef DEBUG |
126 if (strlen(FLAG_stop_at) > 0 && | 128 if (strlen(FLAG_stop_at) > 0 && |
127 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { | 129 info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
128 __ int3(); | 130 __ int3(); |
129 } | 131 } |
130 #endif | 132 #endif |
131 | 133 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 EmitReturnSequence(); | 318 EmitReturnSequence(); |
317 } | 319 } |
318 } | 320 } |
319 | 321 |
320 | 322 |
321 void FullCodeGenerator::ClearAccumulator() { | 323 void FullCodeGenerator::ClearAccumulator() { |
322 __ Set(eax, Immediate(Smi::FromInt(0))); | 324 __ Set(eax, Immediate(Smi::FromInt(0))); |
323 } | 325 } |
324 | 326 |
325 | 327 |
326 void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) { | 328 void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt, |
| 329 Label* back_edge_target) { |
327 Comment cmnt(masm_, "[ Stack check"); | 330 Comment cmnt(masm_, "[ Stack check"); |
328 Label ok; | 331 Label ok; |
329 ExternalReference stack_limit = | 332 |
330 ExternalReference::address_of_stack_limit(isolate()); | 333 if (FLAG_count_based_interrupts) { |
331 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 334 __ mov(ebx, Immediate(profiling_counter_)); |
332 __ j(above_equal, &ok, Label::kNear); | 335 if (FLAG_weighted_back_edges) { |
333 StackCheckStub stub; | 336 ASSERT(back_edge_target->is_bound()); |
334 __ CallStub(&stub); | 337 int distance = masm_->pc_offset() - back_edge_target->pos(); |
| 338 __ sub(Operand::Cell(profiling_counter_), |
| 339 // weight: ceil(distance/100). |
| 340 // The immediate must be a single (signed) byte to satisfy |
| 341 // assumptions made in Builtins::Generate_OnStackReplacement(). |
| 342 Immediate(Smi::FromInt(Min(127, (distance + 99) / 100)))); |
| 343 } else { |
| 344 __ sub(Operand::Cell(profiling_counter_), Immediate(Smi::FromInt(1))); |
| 345 } |
| 346 __ j(positive, &ok, Label::kNear); |
| 347 InterruptStub stub; |
| 348 __ CallStub(&stub); |
| 349 } else { |
| 350 ExternalReference stack_limit = |
| 351 ExternalReference::address_of_stack_limit(isolate()); |
| 352 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 353 __ j(above_equal, &ok, Label::kNear); |
| 354 StackCheckStub stub; |
| 355 __ CallStub(&stub); |
| 356 } |
| 357 |
335 // Record a mapping of this PC offset to the OSR id. This is used to find | 358 // Record a mapping of this PC offset to the OSR id. This is used to find |
336 // the AST id from the unoptimized code in order to use it as a key into | 359 // the AST id from the unoptimized code in order to use it as a key into |
337 // the deoptimization input data found in the optimized code. | 360 // the deoptimization input data found in the optimized code. |
338 RecordStackCheck(stmt->OsrEntryId()); | 361 RecordStackCheck(stmt->OsrEntryId()); |
339 | 362 |
340 // Loop stack checks can be patched to perform on-stack replacement. In | 363 // Loop stack checks can be patched to perform on-stack replacement. In |
341 // order to decide whether or not to perform OSR we embed the loop depth | 364 // order to decide whether or not to perform OSR we embed the loop depth |
342 // in a test instruction after the call so we can extract it from the OSR | 365 // in a test instruction after the call so we can extract it from the OSR |
343 // builtin. | 366 // builtin. |
344 ASSERT(loop_depth() > 0); | 367 ASSERT(loop_depth() > 0); |
345 __ test(eax, Immediate(Min(loop_depth(), Code::kMaxLoopNestingMarker))); | 368 __ test(eax, Immediate(Min(loop_depth(), Code::kMaxLoopNestingMarker))); |
346 | 369 |
| 370 if (FLAG_count_based_interrupts) { |
| 371 // Reset the countdown. |
| 372 __ mov(Operand::Cell(profiling_counter_), |
| 373 Immediate(Smi::FromInt(FLAG_interrupt_budget))); |
| 374 } |
| 375 |
347 __ bind(&ok); | 376 __ bind(&ok); |
348 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); | 377 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
349 // Record a mapping of the OSR id to this PC. This is used if the OSR | 378 // Record a mapping of the OSR id to this PC. This is used if the OSR |
350 // entry becomes the target of a bailout. We don't expect it to be, but | 379 // entry becomes the target of a bailout. We don't expect it to be, but |
351 // we want it to work if it is. | 380 // we want it to work if it is. |
352 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); | 381 PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
353 } | 382 } |
354 | 383 |
355 | 384 |
356 void FullCodeGenerator::EmitReturnSequence() { | 385 void FullCodeGenerator::EmitReturnSequence() { |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 } | 1083 } |
1055 | 1084 |
1056 // Generate code for the body of the loop. | 1085 // Generate code for the body of the loop. |
1057 Visit(stmt->body()); | 1086 Visit(stmt->body()); |
1058 | 1087 |
1059 // Generate code for going to the next element by incrementing the | 1088 // Generate code for going to the next element by incrementing the |
1060 // index (smi) stored on top of the stack. | 1089 // index (smi) stored on top of the stack. |
1061 __ bind(loop_statement.continue_label()); | 1090 __ bind(loop_statement.continue_label()); |
1062 __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); | 1091 __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
1063 | 1092 |
1064 EmitStackCheck(stmt); | 1093 EmitStackCheck(stmt, &loop); |
1065 __ jmp(&loop); | 1094 __ jmp(&loop); |
1066 | 1095 |
1067 // Remove the pointers stored on the stack. | 1096 // Remove the pointers stored on the stack. |
1068 __ bind(loop_statement.break_label()); | 1097 __ bind(loop_statement.break_label()); |
1069 __ add(esp, Immediate(5 * kPointerSize)); | 1098 __ add(esp, Immediate(5 * kPointerSize)); |
1070 | 1099 |
1071 // Exit and decrement the loop depth. | 1100 // Exit and decrement the loop depth. |
1072 __ bind(&exit); | 1101 __ bind(&exit); |
1073 decrement_loop_depth(); | 1102 decrement_loop_depth(); |
1074 } | 1103 } |
(...skipping 3326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4401 *context_length = 0; | 4430 *context_length = 0; |
4402 return previous_; | 4431 return previous_; |
4403 } | 4432 } |
4404 | 4433 |
4405 | 4434 |
4406 #undef __ | 4435 #undef __ |
4407 | 4436 |
4408 } } // namespace v8::internal | 4437 } } // namespace v8::internal |
4409 | 4438 |
4410 #endif // V8_TARGET_ARCH_IA32 | 4439 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |