src/share/vm/ci/ciEnv.hpp

Tue, 05 Jan 2010 13:05:58 +0100

author
twisti
date
Tue, 05 Jan 2010 13:05:58 +0100
changeset 1572
97125851f396
parent 1515
7c57aead6d3e
child 1573
dd57230ba8fe
permissions
-rw-r--r--

6829187: compiler optimizations required for JSR 292
Summary: C2 implementation for invokedynamic support.
Reviewed-by: kvn, never

duke@435 1 /*
xdono@1279 2 * Copyright 1999-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class CompileTask;
duke@435 26
duke@435 27 // ciEnv
duke@435 28 //
duke@435 29 // This class is the top level broker for requests from the compiler
duke@435 30 // to the VM.
duke@435 31 class ciEnv : StackObj {
duke@435 32 CI_PACKAGE_ACCESS_TO
duke@435 33
duke@435 34 friend class CompileBroker;
duke@435 35 friend class Dependencies; // for get_object, during logging
duke@435 36
duke@435 37 private:
duke@435 38 Arena* _arena; // Alias for _ciEnv_arena except in init_shared_objects()
duke@435 39 Arena _ciEnv_arena;
duke@435 40 int _system_dictionary_modification_counter;
duke@435 41 ciObjectFactory* _factory;
duke@435 42 OopRecorder* _oop_recorder;
duke@435 43 DebugInformationRecorder* _debug_info;
duke@435 44 Dependencies* _dependencies;
duke@435 45 const char* _failure_reason;
duke@435 46 int _compilable;
duke@435 47 bool _break_at_compile;
duke@435 48 int _num_inlined_bytecodes;
duke@435 49 CompileTask* _task; // faster access to CompilerThread::task
duke@435 50 CompileLog* _log; // faster access to CompilerThread::log
duke@435 51 void* _compiler_data; // compiler-specific stuff, if any
duke@435 52
duke@435 53 char* _name_buffer;
duke@435 54 int _name_buffer_len;
duke@435 55
kvn@1215 56 // Cache Jvmti state
kvn@1215 57 bool _jvmti_can_hotswap_or_post_breakpoint;
kvn@1215 58 bool _jvmti_can_examine_or_deopt_anywhere;
kvn@1215 59 bool _jvmti_can_access_local_variables;
kvn@1215 60 bool _jvmti_can_post_exceptions;
kvn@1215 61
kvn@1215 62 // Cache DTrace flags
kvn@1215 63 bool _dtrace_extended_probes;
kvn@1215 64 bool _dtrace_monitor_probes;
kvn@1215 65 bool _dtrace_method_probes;
kvn@1215 66 bool _dtrace_alloc_probes;
kvn@1215 67
duke@435 68 // Distinguished instances of certain ciObjects..
duke@435 69 static ciObject* _null_object_instance;
duke@435 70 static ciMethodKlass* _method_klass_instance;
duke@435 71 static ciSymbolKlass* _symbol_klass_instance;
duke@435 72 static ciKlassKlass* _klass_klass_instance;
duke@435 73 static ciInstanceKlassKlass* _instance_klass_klass_instance;
duke@435 74 static ciTypeArrayKlassKlass* _type_array_klass_klass_instance;
duke@435 75 static ciObjArrayKlassKlass* _obj_array_klass_klass_instance;
duke@435 76
duke@435 77 static ciInstanceKlass* _ArrayStoreException;
duke@435 78 static ciInstanceKlass* _Class;
duke@435 79 static ciInstanceKlass* _ClassCastException;
twisti@1572 80 static ciInstanceKlass* _InvokeDynamic;
duke@435 81 static ciInstanceKlass* _Object;
duke@435 82 static ciInstanceKlass* _Throwable;
duke@435 83 static ciInstanceKlass* _Thread;
duke@435 84 static ciInstanceKlass* _OutOfMemoryError;
duke@435 85 static ciInstanceKlass* _String;
never@1515 86 static ciInstanceKlass* _StringBuffer;
never@1515 87 static ciInstanceKlass* _StringBuilder;
never@1515 88 static ciInstanceKlass* _Integer;
duke@435 89
duke@435 90 static ciSymbol* _unloaded_cisymbol;
duke@435 91 static ciInstanceKlass* _unloaded_ciinstance_klass;
duke@435 92 static ciObjArrayKlass* _unloaded_ciobjarrayklass;
duke@435 93
duke@435 94 static jobject _ArrayIndexOutOfBoundsException_handle;
duke@435 95 static jobject _ArrayStoreException_handle;
duke@435 96 static jobject _ClassCastException_handle;
duke@435 97
duke@435 98 ciInstance* _NullPointerException_instance;
duke@435 99 ciInstance* _ArithmeticException_instance;
duke@435 100 ciInstance* _ArrayIndexOutOfBoundsException_instance;
duke@435 101 ciInstance* _ArrayStoreException_instance;
duke@435 102 ciInstance* _ClassCastException_instance;
duke@435 103
never@1515 104 ciInstance* _the_null_string; // The Java string "null"
never@1515 105 ciInstance* _the_min_jint_string; // The Java string "-2147483648"
never@1515 106
duke@435 107 // Look up a klass by name from a particular class loader (the accessor's).
duke@435 108 // If require_local, result must be defined in that class loader, or NULL.
duke@435 109 // If !require_local, a result from remote class loader may be reported,
duke@435 110 // if sufficient class loader constraints exist such that initiating
duke@435 111 // a class loading request from the given loader is bound to return
duke@435 112 // the class defined in the remote loader (or throw an error).
duke@435 113 //
duke@435 114 // Return an unloaded klass if !require_local and no class at all is found.
duke@435 115 //
duke@435 116 // The CI treats a klass as loaded if it is consistently defined in
duke@435 117 // another loader, even if it hasn't yet been loaded in all loaders
duke@435 118 // that could potentially see it via delegation.
duke@435 119 ciKlass* get_klass_by_name(ciKlass* accessing_klass,
duke@435 120 ciSymbol* klass_name,
duke@435 121 bool require_local);
duke@435 122
duke@435 123 // Constant pool access.
duke@435 124 ciKlass* get_klass_by_index(ciInstanceKlass* loading_klass,
duke@435 125 int klass_index,
duke@435 126 bool& is_accessible);
duke@435 127 ciConstant get_constant_by_index(ciInstanceKlass* loading_klass,
duke@435 128 int constant_index);
duke@435 129 bool is_unresolved_string(ciInstanceKlass* loading_klass,
duke@435 130 int constant_index) const;
duke@435 131 bool is_unresolved_klass(ciInstanceKlass* loading_klass,
duke@435 132 int constant_index) const;
duke@435 133 ciField* get_field_by_index(ciInstanceKlass* loading_klass,
duke@435 134 int field_index);
duke@435 135 ciMethod* get_method_by_index(ciInstanceKlass* loading_klass,
duke@435 136 int method_index, Bytecodes::Code bc);
duke@435 137
duke@435 138 // Implementation methods for loading and constant pool access.
duke@435 139 ciKlass* get_klass_by_name_impl(ciKlass* accessing_klass,
duke@435 140 ciSymbol* klass_name,
duke@435 141 bool require_local);
duke@435 142 ciKlass* get_klass_by_index_impl(ciInstanceKlass* loading_klass,
duke@435 143 int klass_index,
duke@435 144 bool& is_accessible);
duke@435 145 ciConstant get_constant_by_index_impl(ciInstanceKlass* loading_klass,
duke@435 146 int constant_index);
duke@435 147 bool is_unresolved_string_impl (instanceKlass* loading_klass,
duke@435 148 int constant_index) const;
duke@435 149 bool is_unresolved_klass_impl (instanceKlass* loading_klass,
duke@435 150 int constant_index) const;
duke@435 151 ciField* get_field_by_index_impl(ciInstanceKlass* loading_klass,
duke@435 152 int field_index);
duke@435 153 ciMethod* get_method_by_index_impl(ciInstanceKlass* loading_klass,
duke@435 154 int method_index, Bytecodes::Code bc);
twisti@1572 155 ciMethod* get_fake_invokedynamic_method_impl(ciInstanceKlass* accessor,
twisti@1572 156 int index, Bytecodes::Code bc);
duke@435 157
duke@435 158 // Helper methods
duke@435 159 bool check_klass_accessibility(ciKlass* accessing_klass,
duke@435 160 klassOop resolved_klassOop);
duke@435 161 methodOop lookup_method(instanceKlass* accessor,
duke@435 162 instanceKlass* holder,
duke@435 163 symbolOop name,
duke@435 164 symbolOop sig,
duke@435 165 Bytecodes::Code bc);
duke@435 166
duke@435 167 // Get a ciObject from the object factory. Ensures uniqueness
duke@435 168 // of ciObjects.
duke@435 169 ciObject* get_object(oop o) {
duke@435 170 if (o == NULL) {
duke@435 171 return _null_object_instance;
duke@435 172 } else {
duke@435 173 return _factory->get(o);
duke@435 174 }
duke@435 175 }
duke@435 176
duke@435 177 ciMethod* get_method_from_handle(jobject method);
duke@435 178
duke@435 179 ciInstance* get_or_create_exception(jobject& handle, symbolHandle name);
duke@435 180
duke@435 181 // Get a ciMethod representing either an unfound method or
duke@435 182 // a method with an unloaded holder. Ensures uniqueness of
duke@435 183 // the result.
duke@435 184 ciMethod* get_unloaded_method(ciInstanceKlass* holder,
duke@435 185 ciSymbol* name,
duke@435 186 ciSymbol* signature) {
duke@435 187 return _factory->get_unloaded_method(holder, name, signature);
duke@435 188 }
duke@435 189
duke@435 190 // Get a ciKlass representing an unloaded klass.
duke@435 191 // Ensures uniqueness of the result.
duke@435 192 ciKlass* get_unloaded_klass(ciKlass* accessing_klass,
duke@435 193 ciSymbol* name) {
duke@435 194 return _factory->get_unloaded_klass(accessing_klass, name, true);
duke@435 195 }
duke@435 196
duke@435 197 // See if we already have an unloaded klass for the given name
duke@435 198 // or return NULL if not.
duke@435 199 ciKlass *check_get_unloaded_klass(ciKlass* accessing_klass, ciSymbol* name) {
duke@435 200 return _factory->get_unloaded_klass(accessing_klass, name, false);
duke@435 201 }
duke@435 202
duke@435 203 // Get a ciReturnAddress corresponding to the given bci.
duke@435 204 // Ensures uniqueness of the result.
duke@435 205 ciReturnAddress* get_return_address(int bci) {
duke@435 206 return _factory->get_return_address(bci);
duke@435 207 }
duke@435 208
duke@435 209 // Get a ciMethodData representing the methodData for a method
duke@435 210 // with none.
duke@435 211 ciMethodData* get_empty_methodData() {
duke@435 212 return _factory->get_empty_methodData();
duke@435 213 }
duke@435 214
duke@435 215 // General utility : get a buffer of some required length.
duke@435 216 // Used in symbol creation.
duke@435 217 char* name_buffer(int req_len);
duke@435 218
duke@435 219 // Is this thread currently in the VM state?
duke@435 220 static bool is_in_vm();
duke@435 221
duke@435 222 // Helper routine for determining the validity of a compilation
duke@435 223 // with respect to concurrent class loading.
duke@435 224 void check_for_system_dictionary_modification(ciMethod* target);
duke@435 225
duke@435 226 public:
duke@435 227 enum {
duke@435 228 MethodCompilable,
duke@435 229 MethodCompilable_not_at_tier,
duke@435 230 MethodCompilable_never
duke@435 231 };
duke@435 232
duke@435 233 ciEnv(CompileTask* task, int system_dictionary_modification_counter);
duke@435 234 // Used only during initialization of the ci
duke@435 235 ciEnv(Arena* arena);
duke@435 236 ~ciEnv();
duke@435 237
duke@435 238 OopRecorder* oop_recorder() { return _oop_recorder; }
duke@435 239 void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; }
duke@435 240
duke@435 241 DebugInformationRecorder* debug_info() { return _debug_info; }
duke@435 242 void set_debug_info(DebugInformationRecorder* i) { _debug_info = i; }
duke@435 243
duke@435 244 Dependencies* dependencies() { return _dependencies; }
duke@435 245 void set_dependencies(Dependencies* d) { _dependencies = d; }
duke@435 246
duke@435 247 // This is true if the compilation is not going to produce code.
duke@435 248 // (It is reasonable to retry failed compilations.)
duke@435 249 bool failing() { return _failure_reason != NULL; }
duke@435 250
duke@435 251 // Reason this compilation is failing, such as "too many basic blocks".
duke@435 252 const char* failure_reason() { return _failure_reason; }
duke@435 253
duke@435 254 // Return state of appropriate compilability
duke@435 255 int compilable() { return _compilable; }
duke@435 256
duke@435 257 bool break_at_compile() { return _break_at_compile; }
duke@435 258 void set_break_at_compile(bool z) { _break_at_compile = z; }
duke@435 259
kvn@1215 260 // Cache Jvmti state
kvn@1215 261 void cache_jvmti_state();
kvn@1215 262 bool jvmti_can_hotswap_or_post_breakpoint() const { return _jvmti_can_hotswap_or_post_breakpoint; }
kvn@1215 263 bool jvmti_can_examine_or_deopt_anywhere() const { return _jvmti_can_examine_or_deopt_anywhere; }
kvn@1215 264 bool jvmti_can_access_local_variables() const { return _jvmti_can_access_local_variables; }
kvn@1215 265 bool jvmti_can_post_exceptions() const { return _jvmti_can_post_exceptions; }
kvn@1215 266
kvn@1215 267 // Cache DTrace flags
kvn@1215 268 void cache_dtrace_flags();
kvn@1215 269 bool dtrace_extended_probes() const { return _dtrace_extended_probes; }
kvn@1215 270 bool dtrace_monitor_probes() const { return _dtrace_monitor_probes; }
kvn@1215 271 bool dtrace_method_probes() const { return _dtrace_method_probes; }
kvn@1215 272 bool dtrace_alloc_probes() const { return _dtrace_alloc_probes; }
kvn@1215 273
duke@435 274 // The compiler task which has created this env.
duke@435 275 // May be useful to find out compile_id, comp_level, etc.
duke@435 276 CompileTask* task() { return _task; }
duke@435 277 // Handy forwards to the task:
duke@435 278 int comp_level(); // task()->comp_level()
duke@435 279 uint compile_id(); // task()->compile_id()
duke@435 280
duke@435 281 // Register the result of a compilation.
duke@435 282 void register_method(ciMethod* target,
duke@435 283 int entry_bci,
duke@435 284 CodeOffsets* offsets,
duke@435 285 int orig_pc_offset,
duke@435 286 CodeBuffer* code_buffer,
duke@435 287 int frame_words,
duke@435 288 OopMapSet* oop_map_set,
duke@435 289 ExceptionHandlerTable* handler_table,
duke@435 290 ImplicitExceptionTable* inc_table,
duke@435 291 AbstractCompiler* compiler,
duke@435 292 int comp_level,
duke@435 293 bool has_debug_info = true,
duke@435 294 bool has_unsafe_access = false);
duke@435 295
duke@435 296
duke@435 297 // Access to certain well known ciObjects.
duke@435 298 ciInstanceKlass* ArrayStoreException_klass() {
duke@435 299 return _ArrayStoreException;
duke@435 300 }
duke@435 301 ciInstanceKlass* Class_klass() {
duke@435 302 return _Class;
duke@435 303 }
duke@435 304 ciInstanceKlass* ClassCastException_klass() {
duke@435 305 return _ClassCastException;
duke@435 306 }
twisti@1572 307 ciInstanceKlass* InvokeDynamic_klass() {
twisti@1572 308 return _InvokeDynamic;
twisti@1572 309 }
duke@435 310 ciInstanceKlass* Object_klass() {
duke@435 311 return _Object;
duke@435 312 }
duke@435 313 ciInstanceKlass* Throwable_klass() {
duke@435 314 return _Throwable;
duke@435 315 }
duke@435 316 ciInstanceKlass* Thread_klass() {
duke@435 317 return _Thread;
duke@435 318 }
duke@435 319 ciInstanceKlass* OutOfMemoryError_klass() {
duke@435 320 return _OutOfMemoryError;
duke@435 321 }
duke@435 322 ciInstanceKlass* String_klass() {
duke@435 323 return _String;
duke@435 324 }
never@1515 325 ciInstanceKlass* StringBuilder_klass() {
never@1515 326 return _StringBuilder;
never@1515 327 }
never@1515 328 ciInstanceKlass* StringBuffer_klass() {
never@1515 329 return _StringBuffer;
never@1515 330 }
never@1515 331 ciInstanceKlass* Integer_klass() {
never@1515 332 return _Integer;
never@1515 333 }
duke@435 334 ciInstance* NullPointerException_instance() {
duke@435 335 assert(_NullPointerException_instance != NULL, "initialization problem");
duke@435 336 return _NullPointerException_instance;
duke@435 337 }
duke@435 338 ciInstance* ArithmeticException_instance() {
duke@435 339 assert(_ArithmeticException_instance != NULL, "initialization problem");
duke@435 340 return _ArithmeticException_instance;
duke@435 341 }
duke@435 342
duke@435 343 // Lazy constructors:
duke@435 344 ciInstance* ArrayIndexOutOfBoundsException_instance();
duke@435 345 ciInstance* ArrayStoreException_instance();
duke@435 346 ciInstance* ClassCastException_instance();
duke@435 347
never@1515 348 ciInstance* the_null_string();
never@1515 349 ciInstance* the_min_jint_string();
never@1515 350
duke@435 351 static ciSymbol* unloaded_cisymbol() {
duke@435 352 return _unloaded_cisymbol;
duke@435 353 }
duke@435 354 static ciObjArrayKlass* unloaded_ciobjarrayklass() {
duke@435 355 return _unloaded_ciobjarrayklass;
duke@435 356 }
duke@435 357 static ciInstanceKlass* unloaded_ciinstance_klass() {
duke@435 358 return _unloaded_ciinstance_klass;
duke@435 359 }
duke@435 360
duke@435 361 ciKlass* find_system_klass(ciSymbol* klass_name);
duke@435 362 // Note: To find a class from its name string, use ciSymbol::make,
duke@435 363 // but consider adding to vmSymbols.hpp instead.
duke@435 364
duke@435 365 // Use this to make a holder for non-perm compile time constants.
jrose@1424 366 // The resulting array is guaranteed to satisfy "can_be_constant".
jrose@1424 367 ciArray* make_system_array(GrowableArray<ciObject*>* objects);
duke@435 368
duke@435 369 // converts the ciKlass* representing the holder of a method into a
duke@435 370 // ciInstanceKlass*. This is needed since the holder of a method in
duke@435 371 // the bytecodes could be an array type. Basically this converts
duke@435 372 // array types into java/lang/Object and other types stay as they are.
duke@435 373 static ciInstanceKlass* get_instance_klass_for_declared_method_holder(ciKlass* klass);
duke@435 374
duke@435 375 // Return the machine-level offset of o, which must be an element of a.
duke@435 376 // This may be used to form constant-loading expressions in lieu of simpler encodings.
duke@435 377 int array_element_offset_in_bytes(ciArray* a, ciObject* o);
duke@435 378
duke@435 379 // Access to the compile-lifetime allocation arena.
duke@435 380 Arena* arena() { return _arena; }
duke@435 381
duke@435 382 // What is the current compilation environment?
duke@435 383 static ciEnv* current() { return CompilerThread::current()->env(); }
duke@435 384
duke@435 385 // Overload with current thread argument
duke@435 386 static ciEnv* current(CompilerThread *thread) { return thread->env(); }
duke@435 387
duke@435 388 // Per-compiler data. (Used by C2 to publish the Compile* pointer.)
duke@435 389 void* compiler_data() { return _compiler_data; }
duke@435 390 void set_compiler_data(void* x) { _compiler_data = x; }
duke@435 391
duke@435 392 // Notice that a method has been inlined in the current compile;
duke@435 393 // used only for statistics.
duke@435 394 void notice_inlined_method(ciMethod* method);
duke@435 395
duke@435 396 // Total number of bytecodes in inlined methods in this compile
duke@435 397 int num_inlined_bytecodes() const;
duke@435 398
duke@435 399 // Output stream for logging compilation info.
duke@435 400 CompileLog* log() { return _log; }
duke@435 401 void set_log(CompileLog* log) { _log = log; }
duke@435 402
duke@435 403 // Check for changes to the system dictionary during compilation
duke@435 404 bool system_dictionary_modification_counter_changed();
duke@435 405
duke@435 406 void record_failure(const char* reason);
duke@435 407 void record_method_not_compilable(const char* reason, bool all_tiers = true);
duke@435 408 void record_out_of_memory_failure();
duke@435 409 };

mercurial