comparison src/share/vm/jvmci/jvmciCodeInstaller.cpp @ 22538:ea6d1727fdc6

Remove BufferBlob from JavaThread and allocate as needed during compilation
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 08 Sep 2015 16:41:04 -0700
parents dc1aeef79e7e
children b87d1bf3cd9a
comparison
equal deleted inserted replaced
22537:9554ce7b6eb5 22538:ea6d1727fdc6
388 } 388 }
389 } 389 }
390 390
391 // constructor used to create a method 391 // constructor used to create a method
392 JVMCIEnv::CodeInstallResult CodeInstaller::install(Handle target, Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log) { 392 JVMCIEnv::CodeInstallResult CodeInstaller::install(Handle target, Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle speculation_log) {
393 BufferBlob* buffer_blob = JVMCIRuntime::initialize_buffer_blob(); 393 CodeBuffer buffer("JVMCI Compiler CodeBuffer");
394 if (buffer_blob == NULL) {
395 return JVMCIEnv::cache_full;
396 }
397
398 CodeBuffer buffer(buffer_blob);
399 jobject compiled_code_obj = JNIHandles::make_local(compiled_code()); 394 jobject compiled_code_obj = JNIHandles::make_local(compiled_code());
400 initialize_dependencies(JNIHandles::resolve(compiled_code_obj)); 395 initialize_dependencies(JNIHandles::resolve(compiled_code_obj));
401 396
402 // Get instructions and constants CodeSections early because we need it. 397 // Get instructions and constants CodeSections early because we need it.
403 _instructions = buffer.insts(); 398 _instructions = buffer.insts();
404 _constants = buffer.consts(); 399 _constants = buffer.consts();
405 400
406 { 401 initialize_fields(target(), JNIHandles::resolve(compiled_code_obj));
407 jobject target_obj = JNIHandles::make_local(target()); 402 JVMCIEnv::CodeInstallResult result = initialize_buffer(buffer);
408 initialize_fields(JNIHandles::resolve(target_obj), JNIHandles::resolve(compiled_code_obj)); 403 if (result != JVMCIEnv::ok) {
409 if (!initialize_buffer(buffer)) { 404 return result;
410 return JVMCIEnv::code_too_large; 405 }
411 } 406 process_exception_handlers();
412 process_exception_handlers();
413 }
414 407
415 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words 408 int stack_slots = _total_frame_size / HeapWordSize; // conversion to words
416 409
417 JVMCIEnv::CodeInstallResult result;
418 if (!compiled_code->is_a(HotSpotCompiledNmethod::klass())) { 410 if (!compiled_code->is_a(HotSpotCompiledNmethod::klass())) {
419 oop stubName = HotSpotCompiledCode::name(compiled_code_obj); 411 oop stubName = HotSpotCompiledCode::name(compiled_code_obj);
420 char* name = strdup(java_lang_String::as_utf8_string(stubName)); 412 char* name = strdup(java_lang_String::as_utf8_string(stubName));
421 cb = RuntimeStub::new_runtime_stub(name, 413 cb = RuntimeStub::new_runtime_stub(name,
422 &buffer, 414 &buffer,
486 478
487 oop arch = TargetDescription::arch(target); 479 oop arch = TargetDescription::arch(target);
488 _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch)); 480 _word_kind_handle = JNIHandles::make_local(Architecture::wordKind(arch));
489 } 481 }
490 482
491 int CodeInstaller::estimate_stub_entries() { 483 int CodeInstaller::estimate_stubs_size() {
492 // Estimate the number of static call stubs that might be emitted. 484 // Estimate the number of static call stubs that might be emitted.
493 int static_call_stubs = 0; 485 int static_call_stubs = 0;
494 objArrayOop sites = this->sites(); 486 objArrayOop sites = this->sites();
495 for (int i = 0; i < sites->length(); i++) { 487 for (int i = 0; i < sites->length(); i++) {
496 oop site = sites->obj_at(i); 488 oop site = sites->obj_at(i);
503 static_call_stubs++; 495 static_call_stubs++;
504 } 496 }
505 } 497 }
506 } 498 }
507 } 499 }
508 return static_call_stubs; 500 return static_call_stubs * CompiledStaticCall::to_interp_stub_size();
509 } 501 }
510 502
511 // perform data and call relocation on the CodeBuffer 503 // perform data and call relocation on the CodeBuffer
512 bool CodeInstaller::initialize_buffer(CodeBuffer& buffer) { 504 JVMCIEnv::CodeInstallResult CodeInstaller::initialize_buffer(CodeBuffer& buffer) {
513 HandleMark hm; 505 HandleMark hm;
514 objArrayHandle sites = this->sites(); 506 objArrayHandle sites = this->sites();
515 int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo)); 507 int locs_buffer_size = sites->length() * (relocInfo::length_limit + sizeof(relocInfo));
516 char* locs_buffer = NEW_RESOURCE_ARRAY(char, locs_buffer_size); 508
517 buffer.insts()->initialize_shared_locs((relocInfo*)locs_buffer, locs_buffer_size / sizeof(relocInfo));
518 // Allocate enough space in the stub section for the static call 509 // Allocate enough space in the stub section for the static call
519 // stubs. Stubs have extra relocs but they are managed by the stub 510 // stubs. Stubs have extra relocs but they are managed by the stub
520 // section itself so they don't need to be accounted for in the 511 // section itself so they don't need to be accounted for in the
521 // locs_buffer above. 512 // locs_buffer above.
522 buffer.initialize_stubs_size(estimate_stub_entries() * CompiledStaticCall::to_interp_stub_size()); 513 int stubs_size = estimate_stubs_size();
514 int total_size = round_to(_code_size, buffer.insts()->alignment()) + round_to(_constants_size, buffer.consts()->alignment()) + round_to(stubs_size, buffer.stubs()->alignment());
515
516 if (total_size > JVMCINMethodSizeLimit) {
517 return JVMCIEnv::code_too_large;
518 }
519
520 buffer.initialize(total_size, locs_buffer_size);
521 if (buffer.blob() == NULL) {
522 return JVMCIEnv::cache_full;
523 }
524 buffer.initialize_stubs_size(stubs_size);
523 buffer.initialize_consts_size(_constants_size); 525 buffer.initialize_consts_size(_constants_size);
524 526
525 _debug_recorder = new DebugInformationRecorder(_oop_recorder); 527 _debug_recorder = new DebugInformationRecorder(_oop_recorder);
526 _debug_recorder->set_oopmaps(new OopMapSet()); 528 _debug_recorder->set_oopmaps(new OopMapSet());
527 529
532 memcpy(_constants->start(), data_section()->base(T_BYTE), _constants_size); 534 memcpy(_constants->start(), data_section()->base(T_BYTE), _constants_size);
533 _constants->set_end(end_data); 535 _constants->set_end(end_data);
534 536
535 // copy the code into the newly created CodeBuffer 537 // copy the code into the newly created CodeBuffer
536 address end_pc = _instructions->start() + _code_size; 538 address end_pc = _instructions->start() + _code_size;
537 if (!_instructions->allocates2(end_pc)) { 539 guarantee(_instructions->allocates2(end_pc), "initialize should have reserved enough space for all the code");
538 return false;
539 }
540 memcpy(_instructions->start(), code()->base(T_BYTE), _code_size); 540 memcpy(_instructions->start(), code()->base(T_BYTE), _code_size);
541 _instructions->set_end(end_pc); 541 _instructions->set_end(end_pc);
542 542
543 for (int i = 0; i < data_section_patches()->length(); i++) { 543 for (int i = 0; i < data_section_patches()->length(); i++) {
544 Handle patch = data_section_patches()->obj_at(i); 544 Handle patch = data_section_patches()->obj_at(i);
615 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment)); 615 char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment));
616 buffer.block_comment(offset, text); 616 buffer.block_comment(offset, text);
617 } 617 }
618 } 618 }
619 #endif 619 #endif
620 return true; 620 return JVMCIEnv::ok;
621 } 621 }
622 622
623 void CodeInstaller::assumption_NoFinalizableSubclass(Handle assumption) { 623 void CodeInstaller::assumption_NoFinalizableSubclass(Handle assumption) {
624 Handle receiverType_handle = Assumptions_NoFinalizableSubclass::receiverType(assumption()); 624 Handle receiverType_handle = Assumptions_NoFinalizableSubclass::receiverType(assumption());
625 Klass* receiverType = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(receiverType_handle)); 625 Klass* receiverType = java_lang_Class::as_Klass(HotSpotResolvedObjectTypeImpl::javaClass(receiverType_handle));