OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 19 matching lines...) Expand all Loading... |
30 #include "bootstrapper.h" | 30 #include "bootstrapper.h" |
31 #include "code-stubs.h" | 31 #include "code-stubs.h" |
32 #include "factory.h" | 32 #include "factory.h" |
33 #include "gdb-jit.h" | 33 #include "gdb-jit.h" |
34 #include "macro-assembler.h" | 34 #include "macro-assembler.h" |
35 | 35 |
36 namespace v8 { | 36 namespace v8 { |
37 namespace internal { | 37 namespace internal { |
38 | 38 |
39 bool CodeStub::FindCodeInCache(Code** code_out) { | 39 bool CodeStub::FindCodeInCache(Code** code_out) { |
40 int index = HEAP->code_stubs()->FindEntry(GetKey()); | 40 Heap* heap = Isolate::Current()->heap(); |
| 41 int index = heap->code_stubs()->FindEntry(GetKey()); |
41 if (index != NumberDictionary::kNotFound) { | 42 if (index != NumberDictionary::kNotFound) { |
42 *code_out = Code::cast(HEAP->code_stubs()->ValueAt(index)); | 43 *code_out = Code::cast(heap->code_stubs()->ValueAt(index)); |
43 return true; | 44 return true; |
44 } | 45 } |
45 return false; | 46 return false; |
46 } | 47 } |
47 | 48 |
48 | 49 |
49 void CodeStub::GenerateCode(MacroAssembler* masm) { | 50 void CodeStub::GenerateCode(MacroAssembler* masm) { |
50 // Update the static counter each time a new code stub is generated. | 51 // Update the static counter each time a new code stub is generated. |
51 masm->isolate()->counters()->code_stubs()->Increment(); | 52 masm->isolate()->counters()->code_stubs()->Increment(); |
52 | 53 |
(...skipping 26 matching lines...) Expand all Loading... |
79 #endif | 80 #endif |
80 } | 81 } |
81 | 82 |
82 | 83 |
83 int CodeStub::GetCodeKind() { | 84 int CodeStub::GetCodeKind() { |
84 return Code::STUB; | 85 return Code::STUB; |
85 } | 86 } |
86 | 87 |
87 | 88 |
88 Handle<Code> CodeStub::GetCode() { | 89 Handle<Code> CodeStub::GetCode() { |
| 90 Isolate* isolate = Isolate::Current(); |
| 91 Factory* factory = isolate->factory(); |
| 92 Heap* heap = isolate->heap(); |
89 Code* code; | 93 Code* code; |
90 if (!FindCodeInCache(&code)) { | 94 if (!FindCodeInCache(&code)) { |
91 v8::HandleScope scope; | 95 HandleScope scope(isolate); |
92 | 96 |
93 // Generate the new code. | 97 // Generate the new code. |
94 MacroAssembler masm(NULL, 256); | 98 MacroAssembler masm(NULL, 256); |
95 GenerateCode(&masm); | 99 GenerateCode(&masm); |
96 | 100 |
97 // Create the code object. | 101 // Create the code object. |
98 CodeDesc desc; | 102 CodeDesc desc; |
99 masm.GetCode(&desc); | 103 masm.GetCode(&desc); |
100 | 104 |
101 // Copy the generated code into a heap object. | 105 // Copy the generated code into a heap object. |
102 Code::Flags flags = Code::ComputeFlags( | 106 Code::Flags flags = Code::ComputeFlags( |
103 static_cast<Code::Kind>(GetCodeKind()), | 107 static_cast<Code::Kind>(GetCodeKind()), |
104 InLoop(), | 108 InLoop(), |
105 GetICState()); | 109 GetICState()); |
106 Handle<Code> new_object = FACTORY->NewCode( | 110 Handle<Code> new_object = factory->NewCode( |
107 desc, flags, masm.CodeObject(), NeedsImmovableCode()); | 111 desc, flags, masm.CodeObject(), NeedsImmovableCode()); |
108 RecordCodeGeneration(*new_object, &masm); | 112 RecordCodeGeneration(*new_object, &masm); |
109 FinishCode(*new_object); | 113 FinishCode(*new_object); |
110 | 114 |
111 // Update the dictionary and the root in Heap. | 115 // Update the dictionary and the root in Heap. |
112 Handle<NumberDictionary> dict = | 116 Handle<NumberDictionary> dict = |
113 FACTORY->DictionaryAtNumberPut( | 117 factory->DictionaryAtNumberPut( |
114 Handle<NumberDictionary>(HEAP->code_stubs()), | 118 Handle<NumberDictionary>(heap->code_stubs()), |
115 GetKey(), | 119 GetKey(), |
116 new_object); | 120 new_object); |
117 HEAP->public_set_code_stubs(*dict); | 121 heap->public_set_code_stubs(*dict); |
118 | 122 |
119 code = *new_object; | 123 code = *new_object; |
120 } | 124 } |
121 | 125 |
122 ASSERT(!NeedsImmovableCode() || HEAP->lo_space()->Contains(code)); | 126 ASSERT(!NeedsImmovableCode() || heap->lo_space()->Contains(code)); |
123 return Handle<Code>(code); | 127 return Handle<Code>(code, isolate); |
124 } | 128 } |
125 | 129 |
126 | 130 |
127 MaybeObject* CodeStub::TryGetCode() { | 131 MaybeObject* CodeStub::TryGetCode() { |
128 Code* code; | 132 Code* code; |
129 if (!FindCodeInCache(&code)) { | 133 if (!FindCodeInCache(&code)) { |
130 // Generate the new code. | 134 // Generate the new code. |
131 MacroAssembler masm(NULL, 256); | 135 MacroAssembler masm(NULL, 256); |
132 GenerateCode(&masm); | 136 GenerateCode(&masm); |
| 137 Heap* heap = masm.isolate()->heap(); |
133 | 138 |
134 // Create the code object. | 139 // Create the code object. |
135 CodeDesc desc; | 140 CodeDesc desc; |
136 masm.GetCode(&desc); | 141 masm.GetCode(&desc); |
137 | 142 |
138 // Try to copy the generated code into a heap object. | 143 // Try to copy the generated code into a heap object. |
139 Code::Flags flags = Code::ComputeFlags( | 144 Code::Flags flags = Code::ComputeFlags( |
140 static_cast<Code::Kind>(GetCodeKind()), | 145 static_cast<Code::Kind>(GetCodeKind()), |
141 InLoop(), | 146 InLoop(), |
142 GetICState()); | 147 GetICState()); |
143 Object* new_object; | 148 Object* new_object; |
144 { MaybeObject* maybe_new_object = | 149 { MaybeObject* maybe_new_object = |
145 HEAP->CreateCode(desc, flags, masm.CodeObject()); | 150 heap->CreateCode(desc, flags, masm.CodeObject()); |
146 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object; | 151 if (!maybe_new_object->ToObject(&new_object)) return maybe_new_object; |
147 } | 152 } |
148 code = Code::cast(new_object); | 153 code = Code::cast(new_object); |
149 RecordCodeGeneration(code, &masm); | 154 RecordCodeGeneration(code, &masm); |
150 FinishCode(code); | 155 FinishCode(code); |
151 | 156 |
152 // Try to update the code cache but do not fail if unable. | 157 // Try to update the code cache but do not fail if unable. |
153 MaybeObject* maybe_new_object = | 158 MaybeObject* maybe_new_object = |
154 HEAP->code_stubs()->AtNumberPut(GetKey(), code); | 159 heap->code_stubs()->AtNumberPut(GetKey(), code); |
155 if (maybe_new_object->ToObject(&new_object)) { | 160 if (maybe_new_object->ToObject(&new_object)) { |
156 HEAP->public_set_code_stubs(NumberDictionary::cast(new_object)); | 161 heap->public_set_code_stubs(NumberDictionary::cast(new_object)); |
157 } | 162 } |
158 } | 163 } |
159 | 164 |
160 return code; | 165 return code; |
161 } | 166 } |
162 | 167 |
163 | 168 |
164 const char* CodeStub::MajorName(CodeStub::Major major_key, | 169 const char* CodeStub::MajorName(CodeStub::Major major_key, |
165 bool allow_unknown_keys) { | 170 bool allow_unknown_keys) { |
166 switch (major_key) { | 171 switch (major_key) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 OS::SNPrintF(Vector<char>(name_, kMaxNameLength), | 231 OS::SNPrintF(Vector<char>(name_, kMaxNameLength), |
227 "InstanceofStub%s%s%s", | 232 "InstanceofStub%s%s%s", |
228 args, | 233 args, |
229 inline_check, | 234 inline_check, |
230 return_true_false_object); | 235 return_true_false_object); |
231 return name_; | 236 return name_; |
232 } | 237 } |
233 | 238 |
234 | 239 |
235 } } // namespace v8::internal | 240 } } // namespace v8::internal |
OLD | NEW |