src/share/vm/ci/ciEnv.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/ci

src/share/vm/ci/ciEnv.cpp

Print this page
rev 8995 : 8046155: JEP165: Compiler Control
Summary:
Reviewed-by:


  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciConstant.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciField.hpp"
  29 #include "ci/ciInstance.hpp"
  30 #include "ci/ciInstanceKlass.hpp"
  31 #include "ci/ciMethod.hpp"
  32 #include "ci/ciNullObject.hpp"
  33 #include "ci/ciReplay.hpp"
  34 #include "ci/ciUtilities.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/vmSymbols.hpp"
  37 #include "code/codeCache.hpp"
  38 #include "code/scopeDesc.hpp"
  39 #include "compiler/compileBroker.hpp"
  40 #include "compiler/compileLog.hpp"
  41 #include "compiler/compilerOracle.hpp"
  42 #include "gc/shared/collectedHeap.inline.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "memory/allocation.inline.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/universe.inline.hpp"
  47 #include "oops/methodData.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "prims/jvmtiExport.hpp"
  52 #include "runtime/init.hpp"
  53 #include "runtime/reflection.hpp"
  54 #include "runtime/sharedRuntime.hpp"
  55 #include "runtime/thread.inline.hpp"
  56 #include "trace/tracing.hpp"
  57 #include "utilities/dtrace.hpp"
  58 #include "utilities/macros.hpp"
  59 #ifdef COMPILER1
  60 #include "c1/c1_Runtime1.hpp"
  61 #endif


  71 ciObject*              ciEnv::_null_object_instance;
  72 
  73 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
  74 WK_KLASSES_DO(WK_KLASS_DEFN)
  75 #undef WK_KLASS_DEFN
  76 
  77 ciSymbol*        ciEnv::_unloaded_cisymbol = NULL;
  78 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL;
  79 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL;
  80 
  81 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL;
  82 jobject ciEnv::_ArrayStoreException_handle = NULL;
  83 jobject ciEnv::_ClassCastException_handle = NULL;
  84 
  85 #ifndef PRODUCT
  86 static bool firstEnv = true;
  87 #endif /* PRODUCT */
  88 
  89 // ------------------------------------------------------------------
  90 // ciEnv::ciEnv
  91 ciEnv::ciEnv(CompileTask* task, int system_dictionary_modification_counter)
  92   : _ciEnv_arena(mtCompiler) {
  93   VM_ENTRY_MARK;
  94 
  95   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
  96   thread->set_env(this);
  97   assert(ciEnv::current() == this, "sanity");
  98 
  99   _oop_recorder = NULL;
 100   _debug_info = NULL;
 101   _dependencies = NULL;
 102   _failure_reason = NULL;
 103   _compilable = MethodCompilable;
 104   _break_at_compile = false;
 105   _compiler_data = NULL;
 106 #ifndef PRODUCT
 107   assert(!firstEnv, "not initialized properly");
 108 #endif /* !PRODUCT */
 109 
 110   _system_dictionary_modification_counter = system_dictionary_modification_counter;
 111   _num_inlined_bytecodes = 0;
 112   assert(task == NULL || thread->task() == task, "sanity");
 113   _task = task;


 114   _log = NULL;
 115 
 116   // Temporary buffer for creating symbols and such.
 117   _name_buffer = NULL;
 118   _name_buffer_len = 0;
 119 
 120   _arena   = &_ciEnv_arena;
 121   _factory = new (_arena) ciObjectFactory(_arena, 128);
 122 
 123   // Preload commonly referenced system ciObjects.
 124 
 125   // During VM initialization, these instances have not yet been created.
 126   // Assertions ensure that these instances are not accessed before
 127   // their initialization.
 128 
 129   assert(Universe::is_fully_initialized(), "should be complete");
 130 
 131   oop o = Universe::null_ptr_exception_instance();
 132   assert(o != NULL, "should have been initialized");
 133   _NullPointerException_instance = get_object(o)->as_instance();


 144   _jvmti_can_hotswap_or_post_breakpoint = false;
 145   _jvmti_can_access_local_variables = false;
 146   _jvmti_can_post_on_exceptions = false;
 147   _jvmti_can_pop_frame = false;
 148 }
 149 
 150 ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) {
 151   ASSERT_IN_VM;
 152 
 153   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
 154   CompilerThread* current_thread = CompilerThread::current();
 155   assert(current_thread->env() == NULL, "must be");
 156   current_thread->set_env(this);
 157   assert(ciEnv::current() == this, "sanity");
 158 
 159   _oop_recorder = NULL;
 160   _debug_info = NULL;
 161   _dependencies = NULL;
 162   _failure_reason = NULL;
 163   _compilable = MethodCompilable_never;
 164   _break_at_compile = false;
 165   _compiler_data = NULL;

 166 #ifndef PRODUCT
 167   assert(firstEnv, "must be first");
 168   firstEnv = false;
 169 #endif /* !PRODUCT */
 170 
 171   _system_dictionary_modification_counter = 0;
 172   _num_inlined_bytecodes = 0;
 173   _task = NULL;
 174   _log = NULL;
 175 
 176   // Temporary buffer for creating symbols and such.
 177   _name_buffer = NULL;
 178   _name_buffer_len = 0;
 179 
 180   _arena   = arena;
 181   _factory = new (_arena) ciObjectFactory(_arena, 128);
 182 
 183   // Preload commonly referenced system ciObjects.
 184 
 185   // During VM initialization, these instances have not yet been created.


 187   // their initialization.
 188 
 189   assert(Universe::is_fully_initialized(), "must be");
 190 
 191   _NullPointerException_instance = NULL;
 192   _ArithmeticException_instance = NULL;
 193   _ArrayIndexOutOfBoundsException_instance = NULL;
 194   _ArrayStoreException_instance = NULL;
 195   _ClassCastException_instance = NULL;
 196   _the_null_string = NULL;
 197   _the_min_jint_string = NULL;
 198 
 199   _jvmti_can_hotswap_or_post_breakpoint = false;
 200   _jvmti_can_access_local_variables = false;
 201   _jvmti_can_post_on_exceptions = false;
 202   _jvmti_can_pop_frame = false;
 203 }
 204 
 205 ciEnv::~ciEnv() {
 206   CompilerThread* current_thread = CompilerThread::current();











 207   _factory->remove_symbols();
 208   // Need safepoint to clear the env on the thread.  RedefineClasses might
 209   // be reading it.
 210   GUARDED_VM_ENTRY(current_thread->set_env(NULL);)
 211 }
 212 
 213 // ------------------------------------------------------------------
 214 // Cache Jvmti state
 215 void ciEnv::cache_jvmti_state() {
 216   VM_ENTRY_MARK;
 217   // Get Jvmti capabilities under lock to get consistant values.
 218   MutexLocker mu(JvmtiThreadState_lock);
 219   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
 220   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables();
 221   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions();
 222   _jvmti_can_pop_frame                  = JvmtiExport::can_pop_frame();
 223 }
 224 
 225 bool ciEnv::should_retain_local_variables() const {
 226   return _jvmti_can_access_local_variables || _jvmti_can_pop_frame;


1018 
1019       // All buffers in the CodeBuffer are allocated in the CodeCache.
1020       // If the code buffer is created on each compile attempt
1021       // as in C2, then it must be freed.
1022       code_buffer->free_blob();
1023       return;
1024     }
1025 
1026     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1027     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1028 
1029     nm =  nmethod::new_nmethod(method,
1030                                compile_id(),
1031                                entry_bci,
1032                                offsets,
1033                                orig_pc_offset,
1034                                debug_info(), dependencies(), code_buffer,
1035                                frame_words, oop_map_set,
1036                                handler_table, inc_table,
1037                                compiler, comp_level);

1038     // Free codeBlobs
1039     code_buffer->free_blob();
1040 
1041     if (nm != NULL) {








1042       nm->set_has_unsafe_access(has_unsafe_access);
1043       nm->set_has_wide_vectors(has_wide_vectors);
1044 #if INCLUDE_RTM_OPT
1045       nm->set_rtm_state(rtm_state);
1046 #endif
1047 
1048       // Record successful registration.
1049       // (Put nm into the task handle *before* publishing to the Java heap.)
1050       if (task() != NULL) {
1051         task()->set_code(nm);
1052       }
1053 
1054       if (entry_bci == InvocationEntryBci) {
1055         if (TieredCompilation) {
1056           // If there is an old version we're done with it
1057           nmethod* old = method->code();
1058           if (TraceMethodReplacement && old != NULL) {
1059             ResourceMark rm;
1060             char *method_name = method->name_and_sig_as_C_string();
1061             tty->print_cr("Replacing method %s", method_name);




  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciConstant.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciField.hpp"
  29 #include "ci/ciInstance.hpp"
  30 #include "ci/ciInstanceKlass.hpp"
  31 #include "ci/ciMethod.hpp"
  32 #include "ci/ciNullObject.hpp"
  33 #include "ci/ciReplay.hpp"
  34 #include "ci/ciUtilities.hpp"
  35 #include "classfile/systemDictionary.hpp"
  36 #include "classfile/vmSymbols.hpp"
  37 #include "code/codeCache.hpp"
  38 #include "code/scopeDesc.hpp"
  39 #include "compiler/compileBroker.hpp"
  40 #include "compiler/compileLog.hpp"
  41 #include "compiler/compilerDirectives.hpp"
  42 #include "gc/shared/collectedHeap.inline.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "memory/allocation.inline.hpp"
  45 #include "memory/oopFactory.hpp"
  46 #include "memory/universe.inline.hpp"
  47 #include "oops/methodData.hpp"
  48 #include "oops/objArrayKlass.hpp"
  49 #include "oops/objArrayOop.inline.hpp"
  50 #include "oops/oop.inline.hpp"
  51 #include "prims/jvmtiExport.hpp"
  52 #include "runtime/init.hpp"
  53 #include "runtime/reflection.hpp"
  54 #include "runtime/sharedRuntime.hpp"
  55 #include "runtime/thread.inline.hpp"
  56 #include "trace/tracing.hpp"
  57 #include "utilities/dtrace.hpp"
  58 #include "utilities/macros.hpp"
  59 #ifdef COMPILER1
  60 #include "c1/c1_Runtime1.hpp"
  61 #endif


  71 ciObject*              ciEnv::_null_object_instance;
  72 
  73 #define WK_KLASS_DEFN(name, ignore_s, ignore_o) ciInstanceKlass* ciEnv::_##name = NULL;
  74 WK_KLASSES_DO(WK_KLASS_DEFN)
  75 #undef WK_KLASS_DEFN
  76 
  77 ciSymbol*        ciEnv::_unloaded_cisymbol = NULL;
  78 ciInstanceKlass* ciEnv::_unloaded_ciinstance_klass = NULL;
  79 ciObjArrayKlass* ciEnv::_unloaded_ciobjarrayklass = NULL;
  80 
  81 jobject ciEnv::_ArrayIndexOutOfBoundsException_handle = NULL;
  82 jobject ciEnv::_ArrayStoreException_handle = NULL;
  83 jobject ciEnv::_ClassCastException_handle = NULL;
  84 
  85 #ifndef PRODUCT
  86 static bool firstEnv = true;
  87 #endif /* PRODUCT */
  88 
  89 // ------------------------------------------------------------------
  90 // ciEnv::ciEnv
  91 ciEnv::ciEnv(CompileTask* task, DirectiveSet* directive_set, int system_dictionary_modification_counter)
  92   : _ciEnv_arena(mtCompiler) {
  93   VM_ENTRY_MARK;
  94 
  95   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
  96   thread->set_env(this);
  97   assert(ciEnv::current() == this, "sanity");
  98 
  99   _oop_recorder = NULL;
 100   _debug_info = NULL;
 101   _dependencies = NULL;
 102   _failure_reason = NULL;
 103   _compilable = MethodCompilable;

 104   _compiler_data = NULL;
 105 #ifndef PRODUCT
 106   assert(!firstEnv, "not initialized properly");
 107 #endif /* !PRODUCT */
 108 
 109   _system_dictionary_modification_counter = system_dictionary_modification_counter;
 110   _num_inlined_bytecodes = 0;
 111   assert(task == NULL || thread->task() == task, "sanity");
 112   _task = task;
 113   assert(directive_set != NULL, "Must always supply a directive");
 114   _directive_set = directive_set;
 115   _log = NULL;
 116 
 117   // Temporary buffer for creating symbols and such.
 118   _name_buffer = NULL;
 119   _name_buffer_len = 0;
 120 
 121   _arena   = &_ciEnv_arena;
 122   _factory = new (_arena) ciObjectFactory(_arena, 128);
 123 
 124   // Preload commonly referenced system ciObjects.
 125 
 126   // During VM initialization, these instances have not yet been created.
 127   // Assertions ensure that these instances are not accessed before
 128   // their initialization.
 129 
 130   assert(Universe::is_fully_initialized(), "should be complete");
 131 
 132   oop o = Universe::null_ptr_exception_instance();
 133   assert(o != NULL, "should have been initialized");
 134   _NullPointerException_instance = get_object(o)->as_instance();


 145   _jvmti_can_hotswap_or_post_breakpoint = false;
 146   _jvmti_can_access_local_variables = false;
 147   _jvmti_can_post_on_exceptions = false;
 148   _jvmti_can_pop_frame = false;
 149 }
 150 
 151 ciEnv::ciEnv(Arena* arena) : _ciEnv_arena(mtCompiler) {
 152   ASSERT_IN_VM;
 153 
 154   // Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
 155   CompilerThread* current_thread = CompilerThread::current();
 156   assert(current_thread->env() == NULL, "must be");
 157   current_thread->set_env(this);
 158   assert(ciEnv::current() == this, "sanity");
 159 
 160   _oop_recorder = NULL;
 161   _debug_info = NULL;
 162   _dependencies = NULL;
 163   _failure_reason = NULL;
 164   _compilable = MethodCompilable_never;

 165   _compiler_data = NULL;
 166   _directive_set = NULL;
 167 #ifndef PRODUCT
 168   assert(firstEnv, "must be first");
 169   firstEnv = false;
 170 #endif /* !PRODUCT */
 171 
 172   _system_dictionary_modification_counter = 0;
 173   _num_inlined_bytecodes = 0;
 174   _task = NULL;
 175   _log = NULL;
 176 
 177   // Temporary buffer for creating symbols and such.
 178   _name_buffer = NULL;
 179   _name_buffer_len = 0;
 180 
 181   _arena   = arena;
 182   _factory = new (_arena) ciObjectFactory(_arena, 128);
 183 
 184   // Preload commonly referenced system ciObjects.
 185 
 186   // During VM initialization, these instances have not yet been created.


 188   // their initialization.
 189 
 190   assert(Universe::is_fully_initialized(), "must be");
 191 
 192   _NullPointerException_instance = NULL;
 193   _ArithmeticException_instance = NULL;
 194   _ArrayIndexOutOfBoundsException_instance = NULL;
 195   _ArrayStoreException_instance = NULL;
 196   _ClassCastException_instance = NULL;
 197   _the_null_string = NULL;
 198   _the_min_jint_string = NULL;
 199 
 200   _jvmti_can_hotswap_or_post_breakpoint = false;
 201   _jvmti_can_access_local_variables = false;
 202   _jvmti_can_post_on_exceptions = false;
 203   _jvmti_can_pop_frame = false;
 204 }
 205 
 206 ciEnv::~ciEnv() {
 207   CompilerThread* current_thread = CompilerThread::current();
 208   {
 209     MutexLockerEx locker(DirectivesStack_lock, Mutex::_no_safepoint_check_flag);
 210     if (_directive_set != NULL){ // May be null during init
 211       if (_directive_set->is_exclusive_copy()) {
 212         // Old CompilecCmmands forced us to create an exclusive copy
 213         delete _directive_set;
 214       } else {
 215         _directive_set->directive()->dec_refcount();
 216       }
 217     }
 218   }
 219   _factory->remove_symbols();
 220   // Need safepoint to clear the env on the thread.  RedefineClasses might
 221   // be reading it.
 222   GUARDED_VM_ENTRY(current_thread->set_env(NULL);)
 223 }
 224 
 225 // ------------------------------------------------------------------
 226 // Cache Jvmti state
 227 void ciEnv::cache_jvmti_state() {
 228   VM_ENTRY_MARK;
 229   // Get Jvmti capabilities under lock to get consistant values.
 230   MutexLocker mu(JvmtiThreadState_lock);
 231   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
 232   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables();
 233   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions();
 234   _jvmti_can_pop_frame                  = JvmtiExport::can_pop_frame();
 235 }
 236 
 237 bool ciEnv::should_retain_local_variables() const {
 238   return _jvmti_can_access_local_variables || _jvmti_can_pop_frame;


1030 
1031       // All buffers in the CodeBuffer are allocated in the CodeCache.
1032       // If the code buffer is created on each compile attempt
1033       // as in C2, then it must be freed.
1034       code_buffer->free_blob();
1035       return;
1036     }
1037 
1038     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1039     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1040 
1041     nm =  nmethod::new_nmethod(method,
1042                                compile_id(),
1043                                entry_bci,
1044                                offsets,
1045                                orig_pc_offset,
1046                                debug_info(), dependencies(), code_buffer,
1047                                frame_words, oop_map_set,
1048                                handler_table, inc_table,
1049                                compiler, comp_level);
1050 
1051     // Free codeBlobs
1052     code_buffer->free_blob();
1053 
1054     if (nm != NULL) {
1055       bool printnmethods = dirset()->PrintAssemblyOption || dirset()->PrintNMethodsOption;
1056       if (printnmethods || PrintDebugInfo || PrintRelocations || PrintDependencies || PrintExceptionHandlers) {
1057         nm->print_nmethod(printnmethods);
1058       }
1059       if (dirset()->PrintAssemblyOption) {
1060         Disassembler::decode(nm);
1061       }
1062 
1063       nm->set_has_unsafe_access(has_unsafe_access);
1064       nm->set_has_wide_vectors(has_wide_vectors);
1065 #if INCLUDE_RTM_OPT
1066       nm->set_rtm_state(rtm_state);
1067 #endif
1068 
1069       // Record successful registration.
1070       // (Put nm into the task handle *before* publishing to the Java heap.)
1071       if (task() != NULL) {
1072         task()->set_code(nm);
1073       }
1074 
1075       if (entry_bci == InvocationEntryBci) {
1076         if (TieredCompilation) {
1077           // If there is an old version we're done with it
1078           nmethod* old = method->code();
1079           if (TraceMethodReplacement && old != NULL) {
1080             ResourceMark rm;
1081             char *method_name = method->name_and_sig_as_C_string();
1082             tty->print_cr("Replacing method %s", method_name);


src/share/vm/ci/ciEnv.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File