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()), GetICState()); |
| 102 Handle<Code> new_object = factory->NewCode( |
| 103 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
| 104 return new_object; |
| 105 } |
| 106 |
| 107 |
90 Handle<Code> CodeStub::GetCode() { | 108 Handle<Code> CodeStub::GetCode() { |
91 Isolate* isolate = Isolate::Current(); | 109 Isolate* isolate = Isolate::Current(); |
92 Factory* factory = isolate->factory(); | 110 Factory* factory = isolate->factory(); |
93 Heap* heap = isolate->heap(); | 111 Heap* heap = isolate->heap(); |
94 Code* code; | 112 Code* code; |
95 if (UseSpecialCache() | 113 if (UseSpecialCache() |
96 ? FindCodeInSpecialCache(&code, isolate) | 114 ? FindCodeInSpecialCache(&code, isolate) |
97 : FindCodeInCache(&code, isolate)) { | 115 : FindCodeInCache(&code, isolate)) { |
98 ASSERT(IsPregenerated() == code->is_pregenerated()); | 116 ASSERT(IsPregenerated() == code->is_pregenerated()); |
99 return Handle<Code>(code); | 117 return Handle<Code>(code); |
100 } | 118 } |
101 | 119 |
102 { | 120 { |
103 HandleScope scope(isolate); | 121 HandleScope scope(isolate); |
104 | 122 |
105 // Generate the new code. | 123 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()); | 124 new_object->set_major_key(MajorKey()); |
120 FinishCode(new_object); | 125 FinishCode(new_object); |
121 RecordCodeGeneration(*new_object, &masm); | 126 RecordCodeGeneration(*new_object, isolate); |
122 | 127 |
123 #ifdef ENABLE_DISASSEMBLER | 128 #ifdef ENABLE_DISASSEMBLER |
124 if (FLAG_print_code_stubs) { | 129 if (FLAG_print_code_stubs) { |
125 new_object->Disassemble(*GetName()); | 130 new_object->Disassemble(*GetName()); |
126 PrintF("\n"); | 131 PrintF("\n"); |
127 } | 132 } |
128 #endif | 133 #endif |
129 | 134 |
130 if (UseSpecialCache()) { | 135 if (UseSpecialCache()) { |
131 AddToSpecialCache(new_object); | 136 AddToSpecialCache(new_object); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 414 |
410 | 415 |
411 void JSEntryStub::FinishCode(Handle<Code> code) { | 416 void JSEntryStub::FinishCode(Handle<Code> code) { |
412 Handle<FixedArray> handler_table = | 417 Handle<FixedArray> handler_table = |
413 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); | 418 code->GetIsolate()->factory()->NewFixedArray(1, TENURED); |
414 handler_table->set(0, Smi::FromInt(handler_offset_)); | 419 handler_table->set(0, Smi::FromInt(handler_offset_)); |
415 code->set_handler_table(*handler_table); | 420 code->set_handler_table(*handler_table); |
416 } | 421 } |
417 | 422 |
418 | 423 |
419 void KeyedLoadElementStub::Generate(MacroAssembler* masm) { | 424 void KeyedLoadDictionaryElementStub::Generate(MacroAssembler* masm) { |
420 switch (elements_kind_) { | 425 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 } | 426 } |
450 | 427 |
451 | 428 |
452 void KeyedStoreElementStub::Generate(MacroAssembler* masm) { | 429 void KeyedStoreElementStub::Generate(MacroAssembler* masm) { |
453 switch (elements_kind_) { | 430 switch (elements_kind_) { |
454 case FAST_ELEMENTS: | 431 case FAST_ELEMENTS: |
455 case FAST_HOLEY_ELEMENTS: | 432 case FAST_HOLEY_ELEMENTS: |
456 case FAST_SMI_ELEMENTS: | 433 case FAST_SMI_ELEMENTS: |
457 case FAST_HOLEY_SMI_ELEMENTS: { | 434 case FAST_HOLEY_SMI_ELEMENTS: { |
458 KeyedStoreStubCompiler::GenerateStoreFastElement(masm, | 435 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. | 620 // already active, as the hooks won't stack. |
644 if (entry_hook != 0 && entry_hook_ != 0) | 621 if (entry_hook != 0 && entry_hook_ != 0) |
645 return false; | 622 return false; |
646 | 623 |
647 entry_hook_ = entry_hook; | 624 entry_hook_ = entry_hook; |
648 return true; | 625 return true; |
649 } | 626 } |
650 | 627 |
651 | 628 |
652 } } // namespace v8::internal | 629 } } // namespace v8::internal |
OLD | NEW |