Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCodeInstaller.cpp @ 3687:7958ebb561b0
Merge
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 18 Nov 2011 17:20:38 +0100 |
parents | 5c8fc9f05960 5e331d5f760e |
children | f8d7ab42c479 |
comparison
equal
deleted
inserted
replaced
3686:2b7278bec776 | 3687:7958ebb561b0 |
---|---|
175 } else if (type == T_OBJECT) { | 175 } else if (type == T_OBJECT) { |
176 oop obj = CiConstant::object(value); | 176 oop obj = CiConstant::object(value); |
177 if (obj == NULL) { | 177 if (obj == NULL) { |
178 return new ConstantOopWriteValue(NULL); | 178 return new ConstantOopWriteValue(NULL); |
179 } else { | 179 } else { |
180 return new ConstantOopWriteValue(JNIHandles::make_global(obj)); | 180 return new ConstantOopWriteValue(JNIHandles::make_local(obj)); |
181 } | 181 } |
182 } else if (type == T_ADDRESS) { | 182 } else if (type == T_ADDRESS) { |
183 return new ConstantLongValue(prim); | 183 return new ConstantLongValue(prim); |
184 } | 184 } |
185 tty->print("%i", type); | 185 tty->print("%i", type); |
186 } else if (value->is_a(CiVirtualObject::klass())) { | 186 } else if (value->is_a(CiVirtualObject::klass())) { |
187 oop type = CiVirtualObject::type(value); | 187 oop type = CiVirtualObject::type(value); |
188 int id = CiVirtualObject::id(value); | 188 int id = CiVirtualObject::id(value); |
189 ciKlass* klass = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type))); | 189 instanceKlass* klass = instanceKlass::cast(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type))); |
190 assert(klass->is_instance_klass() || klass->is_array_klass(), "Not supported allocation."); | |
191 | 190 |
192 for (jint i = 0; i < objects->length(); i++) { | 191 for (jint i = 0; i < objects->length(); i++) { |
193 ObjectValue* obj = (ObjectValue*) objects->at(i); | 192 ObjectValue* obj = (ObjectValue*) objects->at(i); |
194 if (obj->id() == id) { | 193 if (obj->id() == id) { |
195 return obj; | 194 return obj; |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(klass->constant_encoding())); | 198 ObjectValue* sv = new ObjectValue(id, new ConstantOopWriteValue(JNIHandles::make_local(Thread::current(), klass->as_klassOop()))); |
200 | 199 |
201 arrayOop values = (arrayOop) CiVirtualObject::values(value); | 200 arrayOop values = (arrayOop) CiVirtualObject::values(value); |
202 for (jint i = 0; i < values->length(); i++) { | 201 for (jint i = 0; i < values->length(); i++) { |
203 ((oop*) values->base(T_OBJECT))[i]; | 202 ((oop*) values->base(T_OBJECT))[i]; |
204 } | 203 } |
210 if (cur_second != NULL) { | 209 if (cur_second != NULL) { |
211 sv->field_values()->append(cur_second); | 210 sv->field_values()->append(cur_second); |
212 } | 211 } |
213 sv->field_values()->append(value); | 212 sv->field_values()->append(value); |
214 } | 213 } |
215 | |
216 // uint first_ind = spobj->first_index(); | |
217 // for (uint i = 0; i < spobj->n_fields(); i++) { | |
218 // Node* fld_node = sfn->in(first_ind+i); | |
219 // (void)FillLocArray(sv->field_values()->length(), sfn, fld_node, sv->field_values(), objs); | |
220 // } | |
221 // scval = sv; | |
222 | |
223 objects->append(sv); | 214 objects->append(sv); |
224 return sv; | 215 return sv; |
225 } else { | 216 } else { |
226 value->klass()->print(); | 217 value->klass()->print(); |
227 value->print(); | 218 value->print(); |
228 } | 219 } |
229 ShouldNotReachHere(); | 220 ShouldNotReachHere(); |
230 return NULL; | 221 return NULL; |
231 } | 222 } |
232 | 223 |
233 // constructor used to create a method | 224 void CodeInstaller::initialize_assumptions(oop target_method) { |
234 CodeInstaller::CodeInstaller(Handle target_method, nmethod*& nm, bool install_code) { | |
235 _env = CURRENT_ENV; | |
236 GraalCompiler::initialize_buffer_blob(); | |
237 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | |
238 | |
239 _oop_recorder = new OopRecorder(_env->arena()); | 225 _oop_recorder = new OopRecorder(_env->arena()); |
240 _env->set_oop_recorder(_oop_recorder); | 226 _env->set_oop_recorder(_oop_recorder); |
241 _env->set_dependencies(_dependencies); | 227 _env->set_dependencies(_dependencies); |
242 _dependencies = new Dependencies(_env); | 228 _dependencies = new Dependencies(_env); |
243 Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method)); | 229 Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method)); |
244 if (!assumptions_handle.is_null()) { | 230 if (!assumptions_handle.is_null()) { |
245 objArrayHandle assumptions = (objArrayOop)CiAssumptions::list(assumptions_handle()); | 231 objArrayHandle assumptions(Thread::current(), (objArrayOop)CiAssumptions::list(assumptions_handle())); |
246 for (int i = 0; i < assumptions->length(); ++i) { | 232 int length = assumptions->length(); |
233 for (int i = 0; i < length; ++i) { | |
247 Handle assumption = assumptions->obj_at(i); | 234 Handle assumption = assumptions->obj_at(i); |
248 if (!assumption.is_null()) { | 235 if (!assumption.is_null()) { |
249 if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) { | 236 if (assumption->klass() == CiAssumptions_ConcreteSubtype::klass()) { |
250 assumption_ConcreteSubtype(assumption); | 237 assumption_ConcreteSubtype(assumption); |
251 } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) { | 238 } else if (assumption->klass() == CiAssumptions_ConcreteMethod::klass()) { |
252 assumption_ConcreteMethod(assumption); | 239 assumption_ConcreteMethod(assumption); |
253 } else { | 240 } else { |
254 assumption->print(); | 241 assumption->print(); |
255 fatal("unexpected Assumption subclass"); | 242 fatal("unexpected Assumption subclass"); |
256 } | 243 } |
257 } | 244 } |
258 } | 245 } |
259 } | 246 } |
247 } | |
248 | |
249 // constructor used to create a method | |
250 CodeInstaller::CodeInstaller(Handle& target_method, nmethod*& nm, bool install_code) { | |
251 _env = CURRENT_ENV; | |
252 GraalCompiler::initialize_buffer_blob(); | |
253 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | |
254 jobject target_method_obj = JNIHandles::make_local(target_method()); | |
255 initialize_assumptions(JNIHandles::resolve(target_method_obj)); | |
260 | 256 |
261 { | 257 { |
262 No_Safepoint_Verifier no_safepoint; | 258 No_Safepoint_Verifier no_safepoint; |
263 initialize_fields(target_method); | 259 initialize_fields(JNIHandles::resolve(target_method_obj)); |
264 initialize_buffer(buffer); | 260 initialize_buffer(buffer); |
265 process_exception_handlers(); | 261 process_exception_handlers(); |
266 } | 262 } |
267 | 263 |
268 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer | 264 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer |
269 methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(target_method)); | 265 methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(JNIHandles::resolve(target_method_obj))); |
270 { | 266 { |
271 nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, | 267 nm = GraalEnv::register_method(method, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, |
272 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code); | 268 &_implicit_exception_table, GraalCompiler::instance(), _debug_recorder, _dependencies, NULL, -1, false, false, install_code); |
273 } | 269 } |
274 method->clear_queued_for_compilation(); | 270 method->clear_queued_for_compilation(); |
275 } | 271 } |
276 | 272 |
277 // constructor used to create a stub | 273 // constructor used to create a stub |
278 CodeInstaller::CodeInstaller(Handle target_method, jlong& id) { | 274 CodeInstaller::CodeInstaller(Handle& target_method, jlong& id) { |
279 No_Safepoint_Verifier no_safepoint; | 275 No_Safepoint_Verifier no_safepoint; |
280 _env = CURRENT_ENV; | 276 _env = CURRENT_ENV; |
281 | 277 |
282 _oop_recorder = new OopRecorder(_env->arena()); | 278 _oop_recorder = new OopRecorder(_env->arena()); |
283 _env->set_oop_recorder(_oop_recorder); | 279 _env->set_oop_recorder(_oop_recorder); |
284 initialize_fields(target_method); | 280 initialize_fields(target_method()); |
285 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); | 281 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); |
286 | 282 |
287 // (very) conservative estimate: each site needs a relocation | 283 // (very) conservative estimate: each site needs a relocation |
288 GraalCompiler::initialize_buffer_blob(); | 284 GraalCompiler::initialize_buffer_blob(); |
289 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); | 285 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); |
293 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created | 289 BufferBlob* blob = BufferBlob::create(strdup(cname), &buffer); // this is leaking strings... but only a limited number of stubs will be created |
294 IF_TRACE_graal_3 Disassembler::decode((CodeBlob*) blob); | 290 IF_TRACE_graal_3 Disassembler::decode((CodeBlob*) blob); |
295 id = VmIds::addStub(blob->code_begin()); | 291 id = VmIds::addStub(blob->code_begin()); |
296 } | 292 } |
297 | 293 |
298 void CodeInstaller::initialize_fields(Handle target_method) { | 294 void CodeInstaller::initialize_fields(oop target_method) { |
299 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); | 295 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); |
300 _hotspot_method = HotSpotTargetMethod::method(target_method); | 296 _hotspot_method = HotSpotTargetMethod::method(target_method); |
301 if (_hotspot_method != NULL) { | 297 if (_hotspot_method != NULL) { |
302 _parameter_count = getMethodFromHotSpotMethod(_hotspot_method)->size_of_parameters(); | 298 _parameter_count = getMethodFromHotSpotMethod(_hotspot_method)->size_of_parameters(); |
303 } | 299 } |
361 } | 357 } |
362 } | 358 } |
363 } | 359 } |
364 | 360 |
365 void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) { | 361 void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) { |
366 Handle context_handle = CiAssumptions_ConcreteSubtype::context(assumption); | 362 Handle context_handle = CiAssumptions_ConcreteSubtype::context(assumption()); |
367 Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(assumption); | |
368 | |
369 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle))); | 363 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle))); |
364 | |
365 Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(assumption()); | |
370 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle))); | 366 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle))); |
371 | 367 |
372 _dependencies->assert_leaf_type(type); | 368 _dependencies->assert_leaf_type(type); |
373 if (context != type) { | 369 if (context != type) { |
374 assert(context->is_abstract(), ""); | 370 assert(context->is_abstract(), ""); |
375 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); | 371 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); |
376 } | 372 } |
377 } | 373 } |
378 | 374 |
379 void CodeInstaller::assumption_ConcreteMethod(Handle assumption) { | 375 void CodeInstaller::assumption_ConcreteMethod(Handle assumption) { |
380 Handle context_handle = CiAssumptions_ConcreteMethod::context(assumption); | 376 Handle method_handle = CiAssumptions_ConcreteMethod::method(assumption()); |
381 Handle method_handle = CiAssumptions_ConcreteMethod::method(assumption); | |
382 methodHandle method = getMethodFromHotSpotMethod(method_handle()); | 377 methodHandle method = getMethodFromHotSpotMethod(method_handle()); |
378 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method()); | |
379 | |
380 Handle context_handle = CiAssumptions_ConcreteMethod::context(assumption()); | |
383 methodHandle context = getMethodFromHotSpotMethod(context_handle()); | 381 methodHandle context = getMethodFromHotSpotMethod(context_handle()); |
384 | |
385 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method()); | |
386 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context()); | 382 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context()); |
387 ciKlass* context_klass = c->holder(); | 383 ciKlass* context_klass = c->holder(); |
388 _dependencies->assert_unique_concrete_method(context_klass, m); | 384 _dependencies->assert_unique_concrete_method(context_klass, m); |
389 } | 385 } |
390 | 386 |