comparison src/share/vm/graal/graalCodeInstaller.cpp @ 3685:5c8fc9f05960

Merge
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 18 Nov 2011 13:34:10 +0100
parents 6c04a4f268e5 6e1abd79e7c8
children 7958ebb561b0
comparison
equal deleted inserted replaced
3684:1976ebe361c2 3685:5c8fc9f05960
25 #include "graal/graalCompiler.hpp" 25 #include "graal/graalCompiler.hpp"
26 #include "graal/graalCodeInstaller.hpp" 26 #include "graal/graalCodeInstaller.hpp"
27 #include "graal/graalJavaAccess.hpp" 27 #include "graal/graalJavaAccess.hpp"
28 #include "graal/graalVMEntries.hpp" 28 #include "graal/graalVMEntries.hpp"
29 #include "graal/graalVmIds.hpp" 29 #include "graal/graalVmIds.hpp"
30 #include "graal/graalEnv.hpp"
30 #include "c1/c1_Runtime1.hpp" 31 #include "c1/c1_Runtime1.hpp"
31 #include "classfile/vmSymbols.hpp" 32 #include "classfile/vmSymbols.hpp"
32 #include "vmreg_x86.inline.hpp" 33 #include "vmreg_x86.inline.hpp"
33 34
34 35
230 } 231 }
231 232
232 // constructor used to create a method 233 // constructor used to create a method
233 CodeInstaller::CodeInstaller(Handle target_method, nmethod*& nm, bool install_code) { 234 CodeInstaller::CodeInstaller(Handle target_method, nmethod*& nm, bool install_code) {
234 _env = CURRENT_ENV; 235 _env = CURRENT_ENV;
235 ciMethod *ciMethodObject = NULL;
236 {
237 methodOop method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(target_method));
238 ciMethodObject = (ciMethod *) _env->get_object(method);
239 _parameter_count = method->size_of_parameters();
240
241 No_Safepoint_Verifier no_safepoint;
242
243 initialize_fields(target_method);
244 assert(_hotspot_method != NULL && _name == NULL, "installMethod needs NON-NULL method and NULL name");
245 assert(_hotspot_method->is_a(HotSpotMethodResolved::klass()), "installMethod needs a HotSpotMethodResolved");
246
247 }
248
249 // (very) conservative estimate: each site needs a relocation
250 //CodeBuffer buffer("temp graal method", _total_size, _sites->length() * relocInfo::length_limit);
251 GraalCompiler::initialize_buffer_blob(); 236 GraalCompiler::initialize_buffer_blob();
252 CodeBuffer buffer(JavaThread::current()->get_buffer_blob()); 237 CodeBuffer buffer(JavaThread::current()->get_buffer_blob());
253 initialize_buffer(buffer); 238
254 process_exception_handlers(); 239 _oop_recorder = new OopRecorder(_env->arena());
240 _env->set_oop_recorder(_oop_recorder);
241 _env->set_dependencies(_dependencies);
242 _dependencies = new Dependencies(_env);
243 Handle assumptions_handle = CiTargetMethod::assumptions(HotSpotTargetMethod::targetMethod(target_method));
244 if (!assumptions_handle.is_null()) {
245 objArrayHandle assumptions = (objArrayOop)CiAssumptions::list(assumptions_handle());
246 for (int i = 0; i < assumptions->length(); ++i) {
247 Handle assumption = assumptions->obj_at(i);
248 if (!assumption.is_null()) {
249 if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) {
250 assumption_ConcreteSubtype(assumption);
251 } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) {
252 assumption_ConcreteMethod(assumption);
253 } else {
254 assumption->print();
255 fatal("unexpected Assumption subclass");
256 }
257 }
258 }
259 }
260
261 {
262 No_Safepoint_Verifier no_safepoint;
263 initialize_fields(target_method);
264 initialize_buffer(buffer);
265 process_exception_handlers();
266 }
255 267
256 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer 268 int stack_slots = (_frame_size / HeapWordSize) + 2; // conversion to words, need to add two slots for ret address and frame pointer
257 ThreadToNativeFromVM t((JavaThread*) Thread::current()); 269 methodHandle method = getMethodFromHotSpotMethod(HotSpotTargetMethod::method(target_method));
258 nm = _env->register_method(ciMethodObject, -1, &_offsets, _custom_stack_area_offset, &buffer, stack_slots, _debug_recorder->_oopmaps, &_exception_handler_table, 270 {
259 &_implicit_exception_table, GraalCompiler::instance(), _env->comp_level(), false, false, install_code); 271 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);
273 }
274 method->clear_queued_for_compilation();
260 } 275 }
261 276
262 // constructor used to create a stub 277 // constructor used to create a stub
263 CodeInstaller::CodeInstaller(Handle target_method, jlong& id) { 278 CodeInstaller::CodeInstaller(Handle target_method, jlong& id) {
264 No_Safepoint_Verifier no_safepoint; 279 No_Safepoint_Verifier no_safepoint;
265 _env = CURRENT_ENV; 280 _env = CURRENT_ENV;
266 281
282 _oop_recorder = new OopRecorder(_env->arena());
283 _env->set_oop_recorder(_oop_recorder);
267 initialize_fields(target_method); 284 initialize_fields(target_method);
268 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method"); 285 assert(_hotspot_method == NULL && _name != NULL, "installMethod needs NON-NULL name and NULL method");
269 286
270 // (very) conservative estimate: each site needs a relocation 287 // (very) conservative estimate: each site needs a relocation
271 GraalCompiler::initialize_buffer_blob(); 288 GraalCompiler::initialize_buffer_blob();
279 } 296 }
280 297
281 void CodeInstaller::initialize_fields(Handle target_method) { 298 void CodeInstaller::initialize_fields(Handle target_method) {
282 _citarget_method = HotSpotTargetMethod::targetMethod(target_method); 299 _citarget_method = HotSpotTargetMethod::targetMethod(target_method);
283 _hotspot_method = HotSpotTargetMethod::method(target_method); 300 _hotspot_method = HotSpotTargetMethod::method(target_method);
301 if (_hotspot_method != NULL) {
302 _parameter_count = getMethodFromHotSpotMethod(_hotspot_method)->size_of_parameters();
303 }
284 _name = HotSpotTargetMethod::name(target_method); 304 _name = HotSpotTargetMethod::name(target_method);
285 _sites = (arrayOop) HotSpotTargetMethod::sites(target_method); 305 _sites = (arrayOop) HotSpotTargetMethod::sites(target_method);
286 oop assumptions = CiTargetMethod::assumptions(_citarget_method);
287 if (assumptions != NULL) {
288 _assumptions = (arrayOop) CiAssumptions::list(assumptions);
289 } else {
290 _assumptions = NULL;
291 }
292 _exception_handlers = (arrayOop) HotSpotTargetMethod::exceptionHandlers(target_method); 306 _exception_handlers = (arrayOop) HotSpotTargetMethod::exceptionHandlers(target_method);
293 307
294 _code = (arrayOop) CiTargetMethod::targetCode(_citarget_method); 308 _code = (arrayOop) CiTargetMethod::targetCode(_citarget_method);
295 _code_size = CiTargetMethod::targetCodeSize(_citarget_method); 309 _code_size = CiTargetMethod::targetCodeSize(_citarget_method);
296 _frame_size = CiTargetMethod::frameSize(_citarget_method); 310 _frame_size = CiTargetMethod::frameSize(_citarget_method);
310 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); 324 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size);
311 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo)); 325 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo));
312 buffer.initialize_stubs_size(256); 326 buffer.initialize_stubs_size(256);
313 buffer.initialize_consts_size(_constants_size); 327 buffer.initialize_consts_size(_constants_size);
314 328
315 _oop_recorder = new OopRecorder(_env->arena());
316 _env->set_oop_recorder(_oop_recorder);
317 _debug_recorder = new DebugInformationRecorder(_env->oop_recorder()); 329 _debug_recorder = new DebugInformationRecorder(_env->oop_recorder());
318 _debug_recorder->set_oopmaps(new OopMapSet()); 330 _debug_recorder->set_oopmaps(new OopMapSet());
319 _dependencies = new Dependencies(_env); 331
320
321 _env->set_oop_recorder(_oop_recorder);
322 _env->set_debug_info(_debug_recorder); 332 _env->set_debug_info(_debug_recorder);
323 _env->set_dependencies(_dependencies);
324 buffer.initialize_oop_recorder(_oop_recorder); 333 buffer.initialize_oop_recorder(_oop_recorder);
325 334
326 _instructions = buffer.insts(); 335 _instructions = buffer.insts();
327 _constants = buffer.consts(); 336 _constants = buffer.consts();
328 337
349 site_Mark(buffer, pc_offset, site); 358 site_Mark(buffer, pc_offset, site);
350 } else { 359 } else {
351 fatal("unexpected Site subclass"); 360 fatal("unexpected Site subclass");
352 } 361 }
353 } 362 }
354 363 }
355 364
356 if (_assumptions != NULL) { 365 void CodeInstaller::assumption_ConcreteSubtype(Handle assumption) {
357 oop* assumptions = (oop*) _assumptions->base(T_OBJECT); 366 Handle context_handle = CiAssumptions_ConcreteSubtype::context(assumption);
358 for (int i = 0; i < _assumptions->length(); ++i) { 367 Handle type_handle = CiAssumptions_ConcreteSubtype::subtype(assumption);
359 oop assumption = assumptions[i]; 368
360 if (assumption != NULL) { 369 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_handle)));
361 if (assumption->is_a(CiAssumptions_ConcreteSubtype::klass())) { 370 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_handle)));
362 assumption_ConcreteSubtype(assumption);
363 } else if (assumption->is_a(CiAssumptions_ConcreteMethod::klass())) {
364 assumption_ConcreteMethod(assumption);
365 } else {
366 fatal("unexpected Assumption subclass");
367 }
368 }
369 }
370 }
371 }
372
373 void CodeInstaller::assumption_ConcreteSubtype(oop assumption) {
374 oop context_oop = CiAssumptions_ConcreteSubtype::context(assumption);
375 oop type_oop = CiAssumptions_ConcreteSubtype::subtype(assumption);
376
377 ciKlass* context = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(context_oop)));
378 ciKlass* type = (ciKlass*) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(type_oop)));
379 371
380 _dependencies->assert_leaf_type(type); 372 _dependencies->assert_leaf_type(type);
381 if (context != type) { 373 if (context != type) {
382 assert(context->is_abstract(), ""); 374 assert(context->is_abstract(), "");
383 ThreadToNativeFromVM trans(JavaThread::current());
384 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type); 375 _dependencies->assert_abstract_with_unique_concrete_subtype(context, type);
385 } 376 }
386 } 377 }
387 378
388 void CodeInstaller::assumption_ConcreteMethod(oop assumption) { 379 void CodeInstaller::assumption_ConcreteMethod(Handle assumption) {
389 oop context_oop = CiAssumptions_ConcreteMethod::context(assumption); 380 Handle context_handle = CiAssumptions_ConcreteMethod::context(assumption);
390 oop method_oop = CiAssumptions_ConcreteMethod::method(assumption); 381 Handle method_handle = CiAssumptions_ConcreteMethod::method(assumption);
391 methodOop method = getMethodFromHotSpotMethod(method_oop); 382 methodHandle method = getMethodFromHotSpotMethod(method_handle());
392 methodOop context = getMethodFromHotSpotMethod(context_oop); 383 methodHandle context = getMethodFromHotSpotMethod(context_handle());
393 384
394 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method); 385 ciMethod* m = (ciMethod*) CURRENT_ENV->get_object(method());
395 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context); 386 ciMethod* c = (ciMethod*) CURRENT_ENV->get_object(context());
396 ciKlass* context_klass = c->holder(); 387 ciKlass* context_klass = c->holder();
397 { 388 _dependencies->assert_unique_concrete_method(context_klass, m);
398 ThreadToNativeFromVM trans(JavaThread::current());
399 _dependencies->assert_unique_concrete_method(context_klass, m);
400 }
401 } 389 }
402 390
403 void CodeInstaller::process_exception_handlers() { 391 void CodeInstaller::process_exception_handlers() {
404 // allocate some arrays for use by the collection code. 392 // allocate some arrays for use by the collection code.
405 const int num_handlers = 5; 393 const int num_handlers = 5;
472 frame = code_pos; 460 frame = code_pos;
473 } 461 }
474 462
475 oop hotspot_method = CiCodePos::method(code_pos); 463 oop hotspot_method = CiCodePos::method(code_pos);
476 methodOop method = getMethodFromHotSpotMethod(hotspot_method); 464 methodOop method = getMethodFromHotSpotMethod(hotspot_method);
477 ciMethod *cimethod = (ciMethod *) _env->get_object(method);
478 jint bci = CiCodePos::bci(code_pos); 465 jint bci = CiCodePos::bci(code_pos);
479 bool reexecute; 466 bool reexecute;
480 if (bci == -1) { 467 if (bci == -1) {
481 reexecute = false; 468 reexecute = false;
482 } else { 469 } else {
544 bool throw_exception = false; 531 bool throw_exception = false;
545 if (CiFrame::rethrowException(frame)) { 532 if (CiFrame::rethrowException(frame)) {
546 throw_exception = true; 533 throw_exception = true;
547 } 534 }
548 535
549 _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token); 536 _debug_recorder->describe_scope(pc_offset, method, bci, reexecute, throw_exception, false, false, locals_token, expressions_token, monitors_token);
550 } else { 537 } else {
551 _debug_recorder->describe_scope(pc_offset, cimethod, bci, reexecute, false, false, false, NULL, NULL, NULL); 538 _debug_recorder->describe_scope(pc_offset, method, bci, reexecute, false, false, false, NULL, NULL, NULL);
552 } 539 }
553 } 540 }
554 541
555 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) { 542 void CodeInstaller::site_Safepoint(CodeBuffer& buffer, jint pc_offset, oop site) {
556 oop debug_info = CiTargetMethod_Safepoint::debugInfo(site); 543 oop debug_info = CiTargetMethod_Safepoint::debugInfo(site);