ciEnv.cpp revision 1522
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "incls/_precompiled.incl"
#include "incls/_ciEnv.cpp.incl"
// ciEnv
//
// This class is the top level broker for requests from the compiler
// to the VM.
#ifndef PRODUCT
static bool firstEnv = true;
#endif /* PRODUCT */
// ------------------------------------------------------------------
// ciEnv::ciEnv
// Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
_debug_info = NULL;
_break_at_compile = false;
#ifndef PRODUCT
#endif /* !PRODUCT */
// Temporary buffer for creating symbols and such.
_name_buffer = NULL;
_name_buffer_len = 0;
_arena = &_ciEnv_arena;
// Preload commonly referenced system ciObjects.
// During VM initialization, these instances have not yet been created.
// Assertions ensure that these instances are not accessed before
// their initialization.
}
// Set up ciEnv::current immediately, for the sake of ciObjectFactory, etc.
current_thread->set_env(this);
_debug_info = NULL;
_break_at_compile = false;
#ifndef PRODUCT
firstEnv = false;
#endif /* !PRODUCT */
// Temporary buffer for creating symbols and such.
_name_buffer = NULL;
_name_buffer_len = 0;
// Preload commonly referenced system ciObjects.
// During VM initialization, these instances have not yet been created.
// Assertions ensure that these instances are not accessed before
// their initialization.
}
}
// ------------------------------------------------------------------
// Cache Jvmti state
void ciEnv::cache_jvmti_state() {
// Get Jvmti capabilities under lock to get consistant values.
}
// ------------------------------------------------------------------
// Cache DTrace flags
void ciEnv::cache_dtrace_flags() {
// Need lock?
if (_dtrace_extended_probes) {
_dtrace_monitor_probes = true;
_dtrace_method_probes = true;
_dtrace_alloc_probes = true;
} else {
}
}
// ------------------------------------------------------------------
// helper for lazy exception creation
// Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
if (!HAS_PENDING_EXCEPTION && k != NULL) {
if (!HAS_PENDING_EXCEPTION)
}
if (HAS_PENDING_EXCEPTION) {
} else {
}
}
}
// ------------------------------------------------------------------
// ciEnv::ArrayIndexOutOfBoundsException_instance, etc.
if (_ArrayIndexOutOfBoundsException_instance == NULL) {
}
}
if (_ArrayStoreException_instance == NULL) {
}
return _ArrayStoreException_instance;
}
if (_ClassCastException_instance == NULL) {
}
return _ClassCastException_instance;
}
if (_the_null_string == NULL) {
}
return _the_null_string;
}
if (_the_min_jint_string == NULL) {
}
return _the_min_jint_string;
}
// ------------------------------------------------------------------
// ciEnv::get_method_from_handle
}
// ------------------------------------------------------------------
// ciEnv::make_array
if (HAS_PENDING_EXCEPTION) {
return NULL;
}
for (int i = 0; i < length; i++) {
}
return get_object(a)->as_array();
}
// ------------------------------------------------------------------
// ciEnv::array_element_offset_in_bytes
for (int i = 0; i < length; i++) {
if (a->obj_at(i) == o) return i;
}
return -1;
}
// ------------------------------------------------------------------
// ciEnv::check_klass_accessiblity
//
// Note: the logic of this method should mirror the logic of
// constantPoolOopDesc::verify_constant_pool_resolve.
return true;
}
if (accessing_klass->is_obj_array()) {
}
if (!accessing_klass->is_instance_klass()) {
return true;
}
// Find the element klass, if this is an array.
}
true);
}
return true;
}
// ------------------------------------------------------------------
// ciEnv::get_klass_by_name_impl
bool require_local) {
// Now we need to check the SystemDictionary
// This is a name from a signature. Strip off the trimmings.
}
// Check for prior unloaded klass. The SystemDictionary's answers
// can vary over time but the compiler needs consistency.
if (unloaded_klass != NULL) {
if (require_local) return NULL;
return unloaded_klass;
}
if (accessing_klass != NULL) {
}
// setup up the proper type to return on OOM
} else {
}
if (!require_local) {
} else {
}
// If we fail to find an array klass, look again for its element type.
// The element type may be available either locally or via constraints.
// In either case, if we can find the element type in the system dictionary,
// we must build an array type around it. The CI requires array klasses
// to be loaded if their element klasses are loaded, except when memory
// is exhausted.
// We have an unloaded array.
// Build it on the fly if the element class exists.
// Get element ciKlass recursively.
// Now make an array for it
}
}
if (found_klass != NULL) {
// Found it. Build a CI handle.
}
if (require_local) return NULL;
// Not yet loaded into the VM, or not governed by loader constraints.
// Make a CI representative for it.
}
// ------------------------------------------------------------------
// ciEnv::get_klass_by_name
bool require_local) {
}
// ------------------------------------------------------------------
// ciEnv::get_klass_by_index_impl
//
// Implementation of get_klass_by_index.
int index,
bool& is_accessible,
// The klass has not been inserted into the constant pool.
// Try to look it up by name.
{
// We have to lock the cpool to keep the oop from being resolved
// while we are accessing it.
// The klass has been inserted into the constant pool
// very recently.
} else {
}
}
}
// Not found in constant pool. Use the name to do the lookup.
false);
// Calculate accessibility the hard way.
if (!k->is_loaded()) {
is_accessible = false;
// Loaded only remotely. Not linked yet.
is_accessible = false;
} else {
}
return k;
}
// Check for prior unloaded klass. The SystemDictionary's answers
// can vary over time but the compiler needs consistency.
if (unloaded_klass != NULL) {
is_accessible = false;
return unloaded_klass;
}
// It is known to be accessible, since it was found in the constant pool.
is_accessible = true;
}
// ------------------------------------------------------------------
// ciEnv::get_klass_by_index
//
// Get a klass from the constant pool.
int index,
bool& is_accessible,
}
// ------------------------------------------------------------------
// ciEnv::get_constant_by_index_impl
//
// Implementation of get_constant_by_index().
int pool_index, int cache_index,
bool ignore_will_link;
int index = pool_index;
if (cache_index >= 0) {
}
}
} else {
if (HAS_PENDING_EXCEPTION) {
return ciConstant();
}
}
// 4881222: allow ldc to take a class type
if (HAS_PENDING_EXCEPTION) {
return ciConstant();
}
"must be an instance or array klass ");
} else if (tag.is_method_type()) {
// must execute Java code to link this CP entry into cache[i].f1
} else if (tag.is_method_handle()) {
// must execute Java code to link this CP entry into cache[i].f1
} else {
return ciConstant();
}
}
// ------------------------------------------------------------------
// ciEnv::get_constant_by_index
//
// Pull a constant out of the constant pool. How appropriate.
//
// Implementation note: this query is currently in no way cached.
int pool_index, int cache_index,
}
// ------------------------------------------------------------------
// ciEnv::get_field_by_index_impl
//
// Implementation of get_field_by_index.
//
// Implementation note: the results of field lookups are cached
// in the accessor klass.
int index) {
return field;
} else {
}
return field;
}
}
// ------------------------------------------------------------------
// ciEnv::get_field_by_index
//
// Get a field by index from a klass's constant pool.
int index) {
}
// ------------------------------------------------------------------
// ciEnv::lookup_method
//
// Perform an appropriate method lookup based on accessor, holder,
// name, signature, and bytecode.
switch (bc) {
case Bytecodes::_invokestatic:
break;
case Bytecodes::_invokespecial:
break;
case Bytecodes::_invokeinterface:
h_accessor, true);
break;
case Bytecodes::_invokevirtual:
h_accessor, true);
break;
default: ShouldNotReachHere();
}
return dest_method();
}
// ------------------------------------------------------------------
// ciEnv::get_method_by_index_impl
bool holder_is_accessible;
// Get the method's name and signature.
if (holder_is_accessible) { // Our declared holder is loaded.
if (m != NULL) {
// We found the method.
return get_object(m)->as_method();
}
}
// Either the declared holder was not loaded, or the method could
// not be found. Create a dummy ciMethod to represent the failed
// lookup.
return get_unloaded_method(declared_holder,
}
// ------------------------------------------------------------------
// ciEnv::get_fake_invokedynamic_method_impl
// Compare the following logic with InterpreterRuntime::resolve_invokedynamic.
// FIXME: code generation could allow for null (unlinked) call site
is_resolved = false;
// Call site might not be resolved yet. We could create a real invoker method from the
// compiler, but it is simpler to stop the code path here with an unlinked method.
if (!is_resolved) {
ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
}
// Get the invoker methodOop from the constant pool.
assert(signature_invoker != NULL && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
"correct result from LinkResolver::resolve_invokedynamic");
}
// ------------------------------------------------------------------
// ciEnv::get_instance_klass_for_declared_method_holder
// For the case of <array>.clone(), the method holder can be a ciArrayKlass
// instead of a ciInstanceKlass. For that case simply pretend that the
// declared holder is Object.clone since that's where the call will bottom out.
// A more correct fix would trickle out through many interfaces in CI,
// requiring ciInstanceKlass* to become ciKlass* and many more places would
// require checks to make sure the expected type was found. Given that this
// only occurs for clone() the more extensive fix seems like overkill so
// instead we simply smear the array type into Object.
if (method_holder->is_instance_klass()) {
return method_holder->as_instance_klass();
} else if (method_holder->is_array_klass()) {
return current()->Object_klass();
} else {
}
return NULL;
}
// ------------------------------------------------------------------
// ciEnv::get_method_by_index
} else {
}
}
// ------------------------------------------------------------------
// ciEnv::name_buffer
if (_name_buffer_len < req_len) {
if (_name_buffer == NULL) {
} else {
}
}
return _name_buffer;
}
// ------------------------------------------------------------------
// ciEnv::is_in_vm
}
}
// ------------------------------------------------------------------
// ciEnv::check_for_system_dictionary_modification
// Check for changes to the system dictionary during compilation
// class loads, evolution, breakpoints
if (failing()) return; // no need for further checks
// Dependencies must be checked when the system dictionary changes.
// If logging is enabled all violated dependences will be recorded in
// the log. In debug mode check dependencies even if the system
// dictionary hasn't changed to verify that no invalid dependencies
// were inserted. Any violated dependences in this case are dumped to
// the tty.
bool test_deps = counter_changed;
DEBUG_ONLY(test_deps = true);
if (!test_deps) return;
bool print_failures = false;
int violated = 0;
++violated;
// If there's no log and we're not sanity-checking, we're done.
if (!keep_going) break;
}
}
if (violated != 0) {
record_failure("concurrent class loading");
}
}
// ------------------------------------------------------------------
// ciEnv::register_method
int entry_bci,
int orig_pc_offset,
int frame_words,
int comp_level,
bool has_debug_info,
bool has_unsafe_access) {
{
// To prevent compile queue updates.
// Prevent SystemDictionary::add_to_hierarchy from running
// and invalidating our dependencies until we install this method.
// Change in Jvmti state may invalidate compilation.
if (!failing() &&
( (!jvmti_can_hotswap_or_post_breakpoint() &&
(!jvmti_can_post_on_exceptions() &&
JvmtiExport::can_post_on_exceptions()) )) {
record_failure("Jvmti state change invalidated dependencies");
}
// Change in DTrace flags may invalidate compilation.
if (!failing() &&
( (!dtrace_extended_probes() && ExtendedDTraceProbes) ||
(!dtrace_method_probes() && DTraceMethodProbes) ||
(!dtrace_alloc_probes() && DTraceAllocProbes) )) {
record_failure("DTrace flags change invalidated dependencies");
}
if (!failing()) {
// Log the dependencies which this compilation declares.
}
// Encode the dependencies now, so we can check them right away.
// Check for {class loads, evolution, breakpoints} during compilation
}
if (failing()) {
// While not a true deoptimization, it is a preemptive decompile.
}
// All buffers in the CodeBuffer are allocated in the CodeCache.
// If the code buffer is created on each compile attempt
// as in C2, then it must be freed.
code_buffer->free_blob();
return;
}
compile_id(),
// Free codeBlobs
code_buffer->free_blob();
// stress test 6243940 by immediately making the method
// non-entrant behind the system's back. This has serious
// side effects on the code cache and is not meant for
// general stress testing
}
// The CodeCache is full. Print out warning and disable compilation.
record_failure("code cache is full");
{
}
} else {
// Record successful registration.
// (Put nm into the task handle *before* publishing to the Java heap.)
if (entry_bci == InvocationEntryBci) {
#ifdef TIERED
// If there is an old version we're done with it
}
old->make_not_entrant();
}
#endif // TIERED
if (TraceNMethodInstalls ) {
}
// Allow the code to be executed
} else {
if (TraceNMethodInstalls ) {
}
}
}
}
// JVMTI -- compiled method notification (must be done outside lock)
}
}
// ------------------------------------------------------------------
// ciEnv::find_system_klass
}
// ------------------------------------------------------------------
// ciEnv::comp_level
int ciEnv::comp_level() {
return task()->comp_level();
}
// ------------------------------------------------------------------
// ciEnv::compile_id
return task()->compile_id();
}
// ------------------------------------------------------------------
// ciEnv::notice_inlined_method()
}
// ------------------------------------------------------------------
// ciEnv::num_inlined_bytecodes()
int ciEnv::num_inlined_bytecodes() const {
return _num_inlined_bytecodes;
}
// ------------------------------------------------------------------
// ciEnv::record_failure()
}
if (_failure_reason == NULL) {
// Record the first failure reason.
}
}
// ------------------------------------------------------------------
// ciEnv::record_method_not_compilable()
int new_compilable =
// Only note transitions to a worse state
if (new_compilable > _compilable) {
if (all_tiers) {
} else {
}
}
// Reset failure reason; this one is more important.
}
}
// ------------------------------------------------------------------
// ciEnv::record_out_of_memory_failure()
void ciEnv::record_out_of_memory_failure() {
// If memory is low, we stop compiling methods.
record_method_not_compilable("out of memory");
}