hotspot/src/share/vm/jvmci/jvmciCompilerToVM.cpp
changeset 35499 b79827ea1b9f
parent 35498 392b50de06c6
parent 35123 b0b89d83bcf5
child 35871 607bf949dfb3
child 35606 d873b64009cc
equal deleted inserted replaced
35498:392b50de06c6 35499:b79827ea1b9f
    42 #include "jvmci/jvmciCompilerToVM.hpp"
    42 #include "jvmci/jvmciCompilerToVM.hpp"
    43 #include "jvmci/jvmciCompiler.hpp"
    43 #include "jvmci/jvmciCompiler.hpp"
    44 #include "jvmci/jvmciEnv.hpp"
    44 #include "jvmci/jvmciEnv.hpp"
    45 #include "jvmci/jvmciJavaClasses.hpp"
    45 #include "jvmci/jvmciJavaClasses.hpp"
    46 #include "jvmci/jvmciCodeInstaller.hpp"
    46 #include "jvmci/jvmciCodeInstaller.hpp"
       
    47 #include "jvmci/vmStructs_jvmci.hpp"
    47 #include "gc/g1/heapRegion.hpp"
    48 #include "gc/g1/heapRegion.hpp"
    48 #include "runtime/javaCalls.hpp"
    49 #include "runtime/javaCalls.hpp"
    49 #include "runtime/deoptimization.hpp"
    50 #include "runtime/deoptimization.hpp"
    50 #include "runtime/vframe.hpp"
    51 #include "runtime/vframe.hpp"
    51 #include "runtime/vframe_hp.hpp"
    52 #include "runtime/vframe_hp.hpp"
    83     return (oop)result.get_jobject();
    84     return (oop)result.get_jobject();
    84   }
    85   }
    85   return NULL;
    86   return NULL;
    86 }
    87 }
    87 
    88 
    88 void CompilerToVM::invalidate_installed_code(Handle installedCode, TRAPS) {
    89 extern "C" {
    89   if (installedCode() == NULL) {
    90 extern VMStructEntry* jvmciHotSpotVMStructs;
    90     THROW(vmSymbols::java_lang_NullPointerException());
    91 extern uint64_t jvmciHotSpotVMStructEntryTypeNameOffset;
    91   }
    92 extern uint64_t jvmciHotSpotVMStructEntryFieldNameOffset;
    92   jlong nativeMethod = InstalledCode::address(installedCode);
    93 extern uint64_t jvmciHotSpotVMStructEntryTypeStringOffset;
    93   nmethod* nm = (nmethod*)nativeMethod;
    94 extern uint64_t jvmciHotSpotVMStructEntryIsStaticOffset;
    94   assert(nm == NULL || nm->jvmci_installed_code() == installedCode(), "sanity check");
    95 extern uint64_t jvmciHotSpotVMStructEntryOffsetOffset;
    95   if (nm != NULL && nm->is_alive()) {
    96 extern uint64_t jvmciHotSpotVMStructEntryAddressOffset;
    96     // The nmethod state machinery maintains the link between the
    97 extern uint64_t jvmciHotSpotVMStructEntryArrayStride;
    97     // HotSpotInstalledCode and nmethod* so as long as the nmethod appears to be
    98 
    98     // alive assume there is work to do and deoptimize the nmethod.
    99 extern VMTypeEntry* jvmciHotSpotVMTypes;
    99     nm->mark_for_deoptimization();
   100 extern uint64_t jvmciHotSpotVMTypeEntryTypeNameOffset;
   100     VM_Deoptimize op;
   101 extern uint64_t jvmciHotSpotVMTypeEntrySuperclassNameOffset;
   101     VMThread::execute(&op);
   102 extern uint64_t jvmciHotSpotVMTypeEntryIsOopTypeOffset;
   102   }
   103 extern uint64_t jvmciHotSpotVMTypeEntryIsIntegerTypeOffset;
   103   InstalledCode::set_address(installedCode, 0);
   104 extern uint64_t jvmciHotSpotVMTypeEntryIsUnsignedOffset;
       
   105 extern uint64_t jvmciHotSpotVMTypeEntrySizeOffset;
       
   106 extern uint64_t jvmciHotSpotVMTypeEntryArrayStride;
       
   107 
       
   108 extern VMIntConstantEntry* jvmciHotSpotVMIntConstants;
       
   109 extern uint64_t jvmciHotSpotVMIntConstantEntryNameOffset;
       
   110 extern uint64_t jvmciHotSpotVMIntConstantEntryValueOffset;
       
   111 extern uint64_t jvmciHotSpotVMIntConstantEntryArrayStride;
       
   112 
       
   113 extern VMLongConstantEntry* jvmciHotSpotVMLongConstants;
       
   114 extern uint64_t jvmciHotSpotVMLongConstantEntryNameOffset;
       
   115 extern uint64_t jvmciHotSpotVMLongConstantEntryValueOffset;
       
   116 extern uint64_t jvmciHotSpotVMLongConstantEntryArrayStride;
       
   117 
       
   118 extern VMAddressEntry* jvmciHotSpotVMAddresses;
       
   119 extern uint64_t jvmciHotSpotVMAddressEntryNameOffset;
       
   120 extern uint64_t jvmciHotSpotVMAddressEntryValueOffset;
       
   121 extern uint64_t jvmciHotSpotVMAddressEntryArrayStride;
   104 }
   122 }
   105 
   123 
   106 extern "C" {
   124 int CompilerToVM::Data::InstanceKlass_vtable_start_offset;
   107 extern VMStructEntry* gHotSpotVMStructs;
   125 int CompilerToVM::Data::InstanceKlass_vtable_length_offset;
   108 extern uint64_t gHotSpotVMStructEntryTypeNameOffset;
   126 
   109 extern uint64_t gHotSpotVMStructEntryFieldNameOffset;
   127 int CompilerToVM::Data::Method_extra_stack_entries;
   110 extern uint64_t gHotSpotVMStructEntryTypeStringOffset;
   128 
   111 extern uint64_t gHotSpotVMStructEntryIsStaticOffset;
   129 address CompilerToVM::Data::SharedRuntime_ic_miss_stub;
   112 extern uint64_t gHotSpotVMStructEntryOffsetOffset;
   130 address CompilerToVM::Data::SharedRuntime_handle_wrong_method_stub;
   113 extern uint64_t gHotSpotVMStructEntryAddressOffset;
   131 address CompilerToVM::Data::SharedRuntime_deopt_blob_unpack;
   114 extern uint64_t gHotSpotVMStructEntryArrayStride;
   132 address CompilerToVM::Data::SharedRuntime_deopt_blob_uncommon_trap;
   115 
   133 
   116 extern VMTypeEntry* gHotSpotVMTypes;
   134 size_t CompilerToVM::Data::ThreadLocalAllocBuffer_alignment_reserve;
   117 extern uint64_t gHotSpotVMTypeEntryTypeNameOffset;
   135 
   118 extern uint64_t gHotSpotVMTypeEntrySuperclassNameOffset;
   136 CollectedHeap* CompilerToVM::Data::Universe_collectedHeap;
   119 extern uint64_t gHotSpotVMTypeEntryIsOopTypeOffset;
   137 int CompilerToVM::Data::Universe_base_vtable_size;
   120 extern uint64_t gHotSpotVMTypeEntryIsIntegerTypeOffset;
   138 address CompilerToVM::Data::Universe_narrow_oop_base;
   121 extern uint64_t gHotSpotVMTypeEntryIsUnsignedOffset;
   139 int CompilerToVM::Data::Universe_narrow_oop_shift;
   122 extern uint64_t gHotSpotVMTypeEntrySizeOffset;
   140 address CompilerToVM::Data::Universe_narrow_klass_base;
   123 extern uint64_t gHotSpotVMTypeEntryArrayStride;
   141 int CompilerToVM::Data::Universe_narrow_klass_shift;
   124 
   142 void* CompilerToVM::Data::Universe_non_oop_bits;
   125 extern VMIntConstantEntry* gHotSpotVMIntConstants;
   143 uintptr_t CompilerToVM::Data::Universe_verify_oop_mask;
   126 extern uint64_t gHotSpotVMIntConstantEntryNameOffset;
   144 uintptr_t CompilerToVM::Data::Universe_verify_oop_bits;
   127 extern uint64_t gHotSpotVMIntConstantEntryValueOffset;
   145 
   128 extern uint64_t gHotSpotVMIntConstantEntryArrayStride;
   146 bool       CompilerToVM::Data::_supports_inline_contig_alloc;
   129 
   147 HeapWord** CompilerToVM::Data::_heap_end_addr;
   130 extern VMLongConstantEntry* gHotSpotVMLongConstants;
   148 HeapWord** CompilerToVM::Data::_heap_top_addr;
   131 extern uint64_t gHotSpotVMLongConstantEntryNameOffset;
   149 
   132 extern uint64_t gHotSpotVMLongConstantEntryValueOffset;
   150 jbyte* CompilerToVM::Data::cardtable_start_address;
   133 extern uint64_t gHotSpotVMLongConstantEntryArrayStride;
   151 int CompilerToVM::Data::cardtable_shift;
   134 
   152 
   135 extern VMAddressEntry* gHotSpotVMAddresses;
   153 void CompilerToVM::Data::initialize() {
   136 extern uint64_t gHotSpotVMAddressEntryNameOffset;
   154   InstanceKlass_vtable_start_offset = InstanceKlass::vtable_start_offset();
   137 extern uint64_t gHotSpotVMAddressEntryValueOffset;
   155   InstanceKlass_vtable_length_offset = InstanceKlass::vtable_length_offset() * HeapWordSize;
   138 extern uint64_t gHotSpotVMAddressEntryArrayStride;
   156 
       
   157   Method_extra_stack_entries = Method::extra_stack_entries();
       
   158 
       
   159   SharedRuntime_ic_miss_stub = SharedRuntime::get_ic_miss_stub();
       
   160   SharedRuntime_handle_wrong_method_stub = SharedRuntime::get_handle_wrong_method_stub();
       
   161   SharedRuntime_deopt_blob_unpack = SharedRuntime::deopt_blob()->unpack();
       
   162   SharedRuntime_deopt_blob_uncommon_trap = SharedRuntime::deopt_blob()->uncommon_trap();
       
   163 
       
   164   ThreadLocalAllocBuffer_alignment_reserve = ThreadLocalAllocBuffer::alignment_reserve();
       
   165 
       
   166   Universe_collectedHeap = Universe::heap();
       
   167   Universe_base_vtable_size = Universe::base_vtable_size();
       
   168   Universe_narrow_oop_base = Universe::narrow_oop_base();
       
   169   Universe_narrow_oop_shift = Universe::narrow_oop_shift();
       
   170   Universe_narrow_klass_base = Universe::narrow_klass_base();
       
   171   Universe_narrow_klass_shift = Universe::narrow_klass_shift();
       
   172   Universe_non_oop_bits = Universe::non_oop_word();
       
   173   Universe_verify_oop_mask = Universe::verify_oop_mask();
       
   174   Universe_verify_oop_bits = Universe::verify_oop_bits();
       
   175 
       
   176   _supports_inline_contig_alloc = Universe::heap()->supports_inline_contig_alloc();
       
   177   _heap_end_addr = _supports_inline_contig_alloc ? Universe::heap()->end_addr() : (HeapWord**) -1;
       
   178   _heap_top_addr = _supports_inline_contig_alloc ? Universe::heap()->top_addr() : (HeapWord**) -1;
       
   179 
       
   180   BarrierSet* bs = Universe::heap()->barrier_set();
       
   181   switch (bs->kind()) {
       
   182   case BarrierSet::CardTableModRef:
       
   183   case BarrierSet::CardTableForRS:
       
   184   case BarrierSet::CardTableExtension:
       
   185   case BarrierSet::G1SATBCT:
       
   186   case BarrierSet::G1SATBCTLogging: {
       
   187     jbyte* base = barrier_set_cast<CardTableModRefBS>(bs)->byte_map_base;
       
   188     assert(base != 0, "unexpected byte_map_base");
       
   189     cardtable_start_address = base;
       
   190     cardtable_shift = CardTableModRefBS::card_shift;
       
   191     break;
       
   192   }
       
   193   case BarrierSet::ModRef:
       
   194     cardtable_start_address = 0;
       
   195     cardtable_shift = 0;
       
   196     // No post barriers
       
   197     break;
       
   198   default:
       
   199     ShouldNotReachHere();
       
   200     break;
       
   201   }
   139 }
   202 }
   140 
   203 
   141 // FIXME This is only temporary until the GC code is changed.
       
   142 bool       CompilerToVM::_supports_inline_contig_alloc;
       
   143 HeapWord** CompilerToVM::_heap_end_addr;
       
   144 HeapWord** CompilerToVM::_heap_top_addr;
       
   145 
       
   146 /**
   204 /**
   147  * We put all gHotSpotVM values in an array so we can read them easily from Java.
   205  * We put all jvmciHotSpotVM values in an array so we can read them easily from Java.
   148  */
   206  */
   149 static uintptr_t ciHotSpotVMData[28];
   207 static uintptr_t ciHotSpotVMData[28];
   150 
   208 
   151 C2V_VMENTRY(jlong, initializeConfiguration, (JNIEnv *env, jobject))
   209 C2V_VMENTRY(jlong, initializeConfiguration, (JNIEnv *env, jobject))
   152   ciHotSpotVMData[0] = (uintptr_t) gHotSpotVMStructs;
   210   ciHotSpotVMData[0] = (uintptr_t) jvmciHotSpotVMStructs;
   153   ciHotSpotVMData[1] = gHotSpotVMStructEntryTypeNameOffset;
   211   ciHotSpotVMData[1] = jvmciHotSpotVMStructEntryTypeNameOffset;
   154   ciHotSpotVMData[2] = gHotSpotVMStructEntryFieldNameOffset;
   212   ciHotSpotVMData[2] = jvmciHotSpotVMStructEntryFieldNameOffset;
   155   ciHotSpotVMData[3] = gHotSpotVMStructEntryTypeStringOffset;
   213   ciHotSpotVMData[3] = jvmciHotSpotVMStructEntryTypeStringOffset;
   156   ciHotSpotVMData[4] = gHotSpotVMStructEntryIsStaticOffset;
   214   ciHotSpotVMData[4] = jvmciHotSpotVMStructEntryIsStaticOffset;
   157   ciHotSpotVMData[5] = gHotSpotVMStructEntryOffsetOffset;
   215   ciHotSpotVMData[5] = jvmciHotSpotVMStructEntryOffsetOffset;
   158   ciHotSpotVMData[6] = gHotSpotVMStructEntryAddressOffset;
   216   ciHotSpotVMData[6] = jvmciHotSpotVMStructEntryAddressOffset;
   159   ciHotSpotVMData[7] = gHotSpotVMStructEntryArrayStride;
   217   ciHotSpotVMData[7] = jvmciHotSpotVMStructEntryArrayStride;
   160 
   218 
   161   ciHotSpotVMData[8] = (uintptr_t) gHotSpotVMTypes;
   219   ciHotSpotVMData[8] = (uintptr_t) jvmciHotSpotVMTypes;
   162   ciHotSpotVMData[9] = gHotSpotVMTypeEntryTypeNameOffset;
   220   ciHotSpotVMData[9] = jvmciHotSpotVMTypeEntryTypeNameOffset;
   163   ciHotSpotVMData[10] = gHotSpotVMTypeEntrySuperclassNameOffset;
   221   ciHotSpotVMData[10] = jvmciHotSpotVMTypeEntrySuperclassNameOffset;
   164   ciHotSpotVMData[11] = gHotSpotVMTypeEntryIsOopTypeOffset;
   222   ciHotSpotVMData[11] = jvmciHotSpotVMTypeEntryIsOopTypeOffset;
   165   ciHotSpotVMData[12] = gHotSpotVMTypeEntryIsIntegerTypeOffset;
   223   ciHotSpotVMData[12] = jvmciHotSpotVMTypeEntryIsIntegerTypeOffset;
   166   ciHotSpotVMData[13] = gHotSpotVMTypeEntryIsUnsignedOffset;
   224   ciHotSpotVMData[13] = jvmciHotSpotVMTypeEntryIsUnsignedOffset;
   167   ciHotSpotVMData[14] = gHotSpotVMTypeEntrySizeOffset;
   225   ciHotSpotVMData[14] = jvmciHotSpotVMTypeEntrySizeOffset;
   168   ciHotSpotVMData[15] = gHotSpotVMTypeEntryArrayStride;
   226   ciHotSpotVMData[15] = jvmciHotSpotVMTypeEntryArrayStride;
   169 
   227 
   170   ciHotSpotVMData[16] = (uintptr_t) gHotSpotVMIntConstants;
   228   ciHotSpotVMData[16] = (uintptr_t) jvmciHotSpotVMIntConstants;
   171   ciHotSpotVMData[17] = gHotSpotVMIntConstantEntryNameOffset;
   229   ciHotSpotVMData[17] = jvmciHotSpotVMIntConstantEntryNameOffset;
   172   ciHotSpotVMData[18] = gHotSpotVMIntConstantEntryValueOffset;
   230   ciHotSpotVMData[18] = jvmciHotSpotVMIntConstantEntryValueOffset;
   173   ciHotSpotVMData[19] = gHotSpotVMIntConstantEntryArrayStride;
   231   ciHotSpotVMData[19] = jvmciHotSpotVMIntConstantEntryArrayStride;
   174 
   232 
   175   ciHotSpotVMData[20] = (uintptr_t) gHotSpotVMLongConstants;
   233   ciHotSpotVMData[20] = (uintptr_t) jvmciHotSpotVMLongConstants;
   176   ciHotSpotVMData[21] = gHotSpotVMLongConstantEntryNameOffset;
   234   ciHotSpotVMData[21] = jvmciHotSpotVMLongConstantEntryNameOffset;
   177   ciHotSpotVMData[22] = gHotSpotVMLongConstantEntryValueOffset;
   235   ciHotSpotVMData[22] = jvmciHotSpotVMLongConstantEntryValueOffset;
   178   ciHotSpotVMData[23] = gHotSpotVMLongConstantEntryArrayStride;
   236   ciHotSpotVMData[23] = jvmciHotSpotVMLongConstantEntryArrayStride;
   179 
   237 
   180   ciHotSpotVMData[24] = (uintptr_t) gHotSpotVMAddresses;
   238   ciHotSpotVMData[24] = (uintptr_t) jvmciHotSpotVMAddresses;
   181   ciHotSpotVMData[25] = gHotSpotVMAddressEntryNameOffset;
   239   ciHotSpotVMData[25] = jvmciHotSpotVMAddressEntryNameOffset;
   182   ciHotSpotVMData[26] = gHotSpotVMAddressEntryValueOffset;
   240   ciHotSpotVMData[26] = jvmciHotSpotVMAddressEntryValueOffset;
   183   ciHotSpotVMData[27] = gHotSpotVMAddressEntryArrayStride;
   241   ciHotSpotVMData[27] = jvmciHotSpotVMAddressEntryArrayStride;
   184 
   242 
   185   // FIXME This is only temporary until the GC code is changed.
   243   CompilerToVM::Data::initialize();
   186   CompilerToVM::_supports_inline_contig_alloc = Universe::heap()->supports_inline_contig_alloc();
       
   187   CompilerToVM::_heap_end_addr = CompilerToVM::_supports_inline_contig_alloc ? Universe::heap()->end_addr() : (HeapWord**) -1;
       
   188   CompilerToVM::_heap_top_addr = CompilerToVM::_supports_inline_contig_alloc ? Universe::heap()->top_addr() : (HeapWord**) -1;
       
   189 
   244 
   190   return (jlong) (address) &ciHotSpotVMData;
   245   return (jlong) (address) &ciHotSpotVMData;
   191 C2V_END
   246 C2V_END
   192 
   247 
   193 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jobject jvmci_method))
   248 C2V_VMENTRY(jbyteArray, getBytecode, (JNIEnv *, jobject, jobject jvmci_method))
   687   if (result != JVMCIEnv::ok) {
   742   if (result != JVMCIEnv::ok) {
   688     assert(cb == NULL, "should be");
   743     assert(cb == NULL, "should be");
   689   } else {
   744   } else {
   690     if (!installed_code_handle.is_null()) {
   745     if (!installed_code_handle.is_null()) {
   691       assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
   746       assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
   692       CompilerToVM::invalidate_installed_code(installed_code_handle, CHECK_0);
   747       nmethod::invalidate_installed_code(installed_code_handle, CHECK_0);
   693       InstalledCode::set_address(installed_code_handle, (jlong) cb);
   748       {
   694       InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
   749         // Ensure that all updates to the InstalledCode fields are consistent.
   695       if (cb->is_nmethod()) {
   750         MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
   696         InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point());
   751         InstalledCode::set_address(installed_code_handle, (jlong) cb);
   697       } else {
   752         InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
   698         InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin());
   753         if (cb->is_nmethod()) {
   699       }
   754           InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point());
   700       if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
   755         } else {
   701         HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
   756           InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin());
   702         HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
   757         }
   703         HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
   758         if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
       
   759           HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
       
   760           HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
       
   761           HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
       
   762         }
   704       }
   763       }
   705       nmethod* nm = cb->as_nmethod_or_null();
   764       nmethod* nm = cb->as_nmethod_or_null();
   706       if (nm != NULL && installed_code_handle->is_scavengable()) {
   765       if (nm != NULL && installed_code_handle->is_scavengable()) {
   707         assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable");
   766         assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable");
   708         if (!UseG1GC) {
   767         if (!UseG1GC) {
   970 C2V_END
  1029 C2V_END
   971 
  1030 
   972 
  1031 
   973 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code))
  1032 C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv*, jobject, jobject installed_code))
   974   Handle installed_code_handle = JNIHandles::resolve(installed_code);
  1033   Handle installed_code_handle = JNIHandles::resolve(installed_code);
   975   CompilerToVM::invalidate_installed_code(installed_code_handle, CHECK);
  1034   nmethod::invalidate_installed_code(installed_code_handle, CHECK);
   976 C2V_END
  1035 C2V_END
   977 
  1036 
   978 C2V_VMENTRY(jobject, readUncompressedOop, (JNIEnv*, jobject, jlong addr))
  1037 C2V_VMENTRY(jobject, readUncompressedOop, (JNIEnv*, jobject, jlong addr))
   979   oop ret = oopDesc::load_decode_heap_oop((oop*)(address)addr);
  1038   oop ret = oopDesc::load_decode_heap_oop((oop*)(address)addr);
   980   return JNIHandles::make_local(THREAD, ret);
  1039   return JNIHandles::make_local(THREAD, ret);