src/share/vm/ci/ciEnv.hpp

Wed, 12 Oct 2011 21:00:13 -0700

author
twisti
date
Wed, 12 Oct 2011 21:00:13 -0700
changeset 3197
5eb9169b1a14
parent 3099
c124e2e7463e
child 3499
aa3d708d67c4
permissions
-rw-r--r--

7092712: JSR 292: unloaded invokedynamic call sites can lead to a crash with signature types not on BCP
Reviewed-by: jrose, never

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

mercurial