Chromium Code Reviews| 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 30 matching lines...) Expand all Loading... | |
| 41 UnseededNumberDictionary* stubs = isolate->heap()->code_stubs(); | 41 UnseededNumberDictionary* stubs = isolate->heap()->code_stubs(); |
| 42 int index = stubs->FindEntry(GetKey()); | 42 int index = stubs->FindEntry(GetKey()); |
| 43 if (index != UnseededNumberDictionary::kNotFound) { | 43 if (index != UnseededNumberDictionary::kNotFound) { |
| 44 *code_out = Code::cast(stubs->ValueAt(index)); | 44 *code_out = Code::cast(stubs->ValueAt(index)); |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 void CodeStub::GenerateCode(MacroAssembler* masm) { | |
| 52 // Update the static counter each time a new code stub is generated. | |
| 53 masm->isolate()->counters()->code_stubs()->Increment(); | |
| 54 | |
| 55 // Nested stubs are not allowed for leaves. | |
| 56 AllowStubCallsScope allow_scope(masm, false); | |
| 57 | |
| 58 // Generate the code for the stub. | |
| 59 masm->set_generating_stub(true); | |
| 60 NoCurrentFrameScope scope(masm); | |
| 61 Generate(masm); | |
| 62 } | |
| 63 | |
| 64 | |
| 65 SmartArrayPointer<const char> CodeStub::GetName() { | 51 SmartArrayPointer<const char> CodeStub::GetName() { |
| 66 char buffer[100]; | 52 char buffer[100]; |
| 67 NoAllocationStringAllocator allocator(buffer, | 53 NoAllocationStringAllocator allocator(buffer, |
| 68 static_cast<unsigned>(sizeof(buffer))); | 54 static_cast<unsigned>(sizeof(buffer))); |
| 69 StringStream stream(&allocator); | 55 StringStream stream(&allocator); |
| 70 PrintName(&stream); | 56 PrintName(&stream); |
| 71 return stream.ToCString(); | 57 return stream.ToCString(); |
| 72 } | 58 } |
| 73 | 59 |
| 74 | 60 |
| 75 void CodeStub::RecordCodeGeneration(Code* code, MacroAssembler* masm) { | 61 void CodeStub::RecordCodeGeneration(Code* code, Isolate* isolate) { |
| 76 Isolate* isolate = masm->isolate(); | |
| 77 SmartArrayPointer<const char> name = GetName(); | 62 SmartArrayPointer<const char> name = GetName(); |
| 78 PROFILE(isolate, CodeCreateEvent(Logger::STUB_TAG, code, *name)); | 63 PROFILE(isolate, CodeCreateEvent(Logger::STUB_TAG, code, *name)); |
| 79 GDBJIT(AddCode(GDBJITInterface::STUB, *name, code)); | 64 GDBJIT(AddCode(GDBJITInterface::STUB, *name, code)); |
| 80 Counters* counters = isolate->counters(); | 65 Counters* counters = isolate->counters(); |
| 81 counters->total_stubs_code_size()->Increment(code->instruction_size()); | 66 counters->total_stubs_code_size()->Increment(code->instruction_size()); |
| 82 } | 67 } |
| 83 | 68 |
| 84 | 69 |
| 85 int CodeStub::GetCodeKind() { | 70 int CodeStub::GetCodeKind() { |
| 86 return Code::STUB; | 71 return Code::STUB; |
| 87 } | 72 } |
| 88 | 73 |
| 89 | 74 |
| 75 Handle<Code> PlatformCodeStub::GenerateCode() { | |
| 76 Isolate* isolate = Isolate::Current(); | |
| 77 Factory* factory = isolate->factory(); | |
| 78 | |
| 79 // Generate the new code. | |
| 80 MacroAssembler masm(isolate, NULL, 256); | |
| 81 | |
| 82 { | |
| 83 // Update the static counter each time a new code stub is generated. | |
| 84 isolate->counters()->code_stubs()->Increment(); | |
| 85 | |
| 86 // Nested stubs are not allowed for leaves. | |
| 87 AllowStubCallsScope allow_scope(&masm, false); | |
| 88 | |
| 89 // Generate the code for the stub. | |
| 90 masm.set_generating_stub(true); | |
| 91 NoCurrentFrameScope scope(&masm); | |
| 92 Generate(&masm); | |
| 93 } | |
| 94 | |
| 95 // Create the code object. | |
| 96 CodeDesc desc; | |
| 97 masm.GetCode(&desc); | |
| 98 | |
| 99 // Copy the generated code into a heap object. | |
| 100 Code::Flags flags = Code::ComputeFlags( | |
| 101 static_cast<Code::Kind>(GetCodeKind()), | |
| 102 GetICState()); | |
|
Jakob Kummerow
2012/11/28 16:28:22
nit: fits on previous line?
danno
2012/11/30 16:23:24
Done.
| |
| 103 Handle<Code> new_object = factory->NewCode( | |
| 104 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | |
| 105 return new_object; | |
| 106 } | |
| 107 | |
| 108 | |
| 90 Handle<Code> CodeStub::GetCode() { | 109 Handle<Code> CodeStub::GetCode() { |
| 91 Isolate* isolate = Isolate::Current(); | 110 Isolate* isolate = Isolate::Current(); |
| 92 Factory* factory = isolate->factory(); | 111 Factory* factory = isolate->factory(); |
| 93 Heap* heap = isolate->heap(); | 112 Heap* heap = isolate->heap(); |
| 94 Code* code; | 113 Code* code; |
| 95 if (UseSpecialCache() | 114 if (UseSpecialCache() |
| 96 ? FindCodeInSpecialCache(&code, isolate) | 115 ? FindCodeInSpecialCache(&code, isolate) |
| 97 : FindCodeInCache(&code, isolate)) { | 116 : FindCodeInCache(&code, isolate)) { |
| 98 ASSERT(IsPregenerated() == code->is_pregenerated()); | 117 ASSERT(IsPregenerated() == code->is_pregenerated()); |
| 99 return Handle<Code>(code); | 118 return Handle<Code>(code); |
| 100 } | 119 } |
| 101 | 120 |
| 102 { | 121 { |
| 103 HandleScope scope(isolate); | 122 HandleScope scope(isolate); |
| 104 | 123 |
| 105 // Generate the new code. | 124 Handle<Code> new_object = GenerateCode(); |
| 106 MacroAssembler masm(isolate, NULL, 256); | |
| 107 GenerateCode(&masm); | |
| 108 | |
| 109 // Create the code object. | |
| 110 CodeDesc desc; | |
| 111 masm.GetCode(&desc); | |
| 112 | |
| 113 // Copy the generated code into a heap object. | |
| 114 Code::Flags flags = Code::ComputeFlags( | |
| 115 static_cast<Code::Kind>(GetCodeKind()), | |
| 116 GetICState()); | |
| 117 Handle<Code> new_object = factory->NewCode( | |
| 118 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | |
| 119 new_object->set_major_key(MajorKey()); | 125 new_object->set_major_key(MajorKey()); |
| 120 FinishCode(new_object); | 126 FinishCode(new_object); |
| 121 RecordCodeGeneration(*new_object, &masm); | 127 RecordCodeGeneration(*new_object, isolate); |
| 122 | 128 |
| 123 #ifdef ENABLE_DISASSEMBLER | 129 #ifdef ENABLE_DISASSEMBLER |
| 124 if (FLAG_print_code_stubs) { | 130 if (FLAG_print_code_stubs) { |
| 125 new_object->Disassemble(*GetName()); | 131 new_object->Disassemble(*GetName()); |
| 126 PrintF("\n"); | 132 PrintF("\n"); |
| 127 } | 133 } |
| 128 #endif | 134 #endif |
| 129 | 135 |
| 130 if (UseSpecialCache()) { | 136 if (UseSpecialCache()) { |
| 131 AddToSpecialCache(new_object); | 137 AddToSpecialCache(new_object); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 | 415 |
| 410 | 416 |
| 411 void JSEntryStub::FinishCode(Handle<Code> code) { | 417 void JSEntryStub::FinishCode(Handle<Code> code) { |
| 412 Handle<FixedArray> handler_table = | 418 Handle<FixedArray> handler_table = |
| 413 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); | 419 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); |
| 414 handler_table->set(0, Smi::FromInt(handler_offset_)); | 420 handler_table->set(0, Smi::FromInt(handler_offset_)); |
| 415 code->set_handler_table(*handler_table); | 421 code->set_handler_table(*handler_table); |
| 416 } | 422 } |
| 417 | 423 |
| 418 | 424 |
| 419 void KeyedLoadElementStub::Generate(MacroAssembler* masm) { | 425 void KeyedLoadDictionaryElementStub::Generate(MacroAssembler* masm) { |
| 420 switch (elements_kind_) { | 426 KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); |
| 421 case FAST_ELEMENTS: | |
| 422 case FAST_HOLEY_ELEMENTS: | |
| 423 case FAST_SMI_ELEMENTS: | |
| 424 case FAST_HOLEY_SMI_ELEMENTS: | |
| 425 KeyedLoadStubCompiler::GenerateLoadFastElement(masm); | |
| 426 break; | |
| 427 case FAST_DOUBLE_ELEMENTS: | |
| 428 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 429 KeyedLoadStubCompiler::GenerateLoadFastDoubleElement(masm); | |
| 430 break; | |
| 431 case EXTERNAL_BYTE_ELEMENTS: | |
| 432 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | |
| 433 case EXTERNAL_SHORT_ELEMENTS: | |
| 434 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | |
| 435 case EXTERNAL_INT_ELEMENTS: | |
| 436 case EXTERNAL_UNSIGNED_INT_ELEMENTS: | |
| 437 case EXTERNAL_FLOAT_ELEMENTS: | |
| 438 case EXTERNAL_DOUBLE_ELEMENTS: | |
| 439 case EXTERNAL_PIXEL_ELEMENTS: | |
| 440 KeyedLoadStubCompiler::GenerateLoadExternalArray(masm, elements_kind_); | |
| 441 break; | |
| 442 case DICTIONARY_ELEMENTS: | |
| 443 KeyedLoadStubCompiler::GenerateLoadDictionaryElement(masm); | |
| 444 break; | |
| 445 case NON_STRICT_ARGUMENTS_ELEMENTS: | |
| 446 UNREACHABLE(); | |
| 447 break; | |
| 448 } | |
| 449 } | 427 } |
| 450 | 428 |
| 451 | 429 |
| 452 void KeyedStoreElementStub::Generate(MacroAssembler* masm) { | 430 void KeyedStoreElementStub::Generate(MacroAssembler* masm) { |
| 453 switch (elements_kind_) { | 431 switch (elements_kind_) { |
| 454 case FAST_ELEMENTS: | 432 case FAST_ELEMENTS: |
| 455 case FAST_HOLEY_ELEMENTS: | 433 case FAST_HOLEY_ELEMENTS: |
| 456 case FAST_SMI_ELEMENTS: | 434 case FAST_SMI_ELEMENTS: |
| 457 case FAST_HOLEY_SMI_ELEMENTS: { | 435 case FAST_HOLEY_SMI_ELEMENTS: { |
| 458 KeyedStoreStubCompiler::GenerateStoreFastElement(masm, | 436 KeyedStoreStubCompiler::GenerateStoreFastElement(masm, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 // already active, as the hooks won't stack. | 621 // already active, as the hooks won't stack. |
| 644 if (entry_hook != 0 && entry_hook_ != 0) | 622 if (entry_hook != 0 && entry_hook_ != 0) |
| 645 return false; | 623 return false; |
| 646 | 624 |
| 647 entry_hook_ = entry_hook; | 625 entry_hook_ = entry_hook; |
| 648 return true; | 626 return true; |
| 649 } | 627 } |
| 650 | 628 |
| 651 | 629 |
| 652 } } // namespace v8::internal | 630 } } // namespace v8::internal |
| OLD | NEW |