< prev index next >

src/hotspot/share/jvmci/jvmciEnv.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  45 #include "oops/oop.inline.hpp"
  46 #include "prims/jvmtiExport.hpp"
  47 #include "runtime/fieldDescriptor.inline.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/init.hpp"
  50 #include "runtime/reflection.hpp"
  51 #include "runtime/sharedRuntime.hpp"
  52 #include "runtime/sweeper.hpp"
  53 #include "utilities/dtrace.hpp"
  54 #include "jvmci/jvmciRuntime.hpp"
  55 #include "jvmci/jvmciJavaClasses.hpp"
  56 
  57 JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter):
  58   _task(task),
  59   _system_dictionary_modification_counter(system_dictionary_modification_counter),
  60   _failure_reason(NULL),
  61   _retryable(true)
  62 {
  63   // Get Jvmti capabilities under lock to get consistent values.
  64   MutexLocker mu(JvmtiThreadState_lock);
  65   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint();
  66   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables();
  67   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions();





















  68 }
  69 
  70 // ------------------------------------------------------------------
  71 // Note: the logic of this method should mirror the logic of
  72 // constantPoolOopDesc::verify_constant_pool_resolve.
  73 bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) {
  74   if (accessing_klass->is_objArray_klass()) {
  75     accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass();
  76   }
  77   if (!accessing_klass->is_instance_klass()) {
  78     return true;
  79   }
  80 
  81   if (resolved_klass->is_objArray_klass()) {
  82     // Find the element klass, if this is an array.
  83     resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
  84   }
  85   if (resolved_klass->is_instance_klass()) {
  86     Reflection::VerifyClassAccessResults result =
  87       Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true);


 395     ShouldNotReachHere();
 396   }
 397   return NULL;
 398 }
 399 
 400 
 401 // ------------------------------------------------------------------
 402 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
 403                                      int index, Bytecodes::Code bc,
 404                                      InstanceKlass* accessor) {
 405   ResourceMark rm;
 406   return get_method_by_index_impl(cpool, index, bc, accessor);
 407 }
 408 
 409 // ------------------------------------------------------------------
 410 // Check for changes to the system dictionary during compilation
 411 // class loads, evolution, breakpoints
 412 JVMCIEnv::CodeInstallResult JVMCIEnv::validate_compile_task_dependencies(Dependencies* dependencies, Handle compiled_code,
 413                                                                          JVMCIEnv* env, char** failure_detail) {
 414   // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
 415   if (env != NULL) {
 416     if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) {
 417       *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation";
 418       return JVMCIEnv::dependencies_failed;
 419     }
 420   }
 421 
 422   // Dependencies must be checked when the system dictionary changes
 423   // or if we don't know whether it has changed (i.e., env == NULL).
 424   bool counter_changed = env == NULL || env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
 425   CompileTask* task = env == NULL ? NULL : env->task();
 426   Dependencies::DepType result = dependencies->validate_dependencies(task, counter_changed, failure_detail);
 427   if (result == Dependencies::end_marker) {
 428     return JVMCIEnv::ok;
 429   }
 430 
 431   if (!Dependencies::is_klass_type(result) || counter_changed) {
 432     return JVMCIEnv::dependencies_failed;
 433   }
 434   // The dependencies were invalid at the time of installation
 435   // without any intervening modification of the system
 436   // dictionary.  That means they were invalidly constructed.
 437   return JVMCIEnv::dependencies_invalid;
 438 }
 439 
 440 // ------------------------------------------------------------------


   1 /*
   2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  45 #include "oops/oop.inline.hpp"
  46 #include "prims/jvmtiExport.hpp"
  47 #include "runtime/fieldDescriptor.inline.hpp"
  48 #include "runtime/handles.inline.hpp"
  49 #include "runtime/init.hpp"
  50 #include "runtime/reflection.hpp"
  51 #include "runtime/sharedRuntime.hpp"
  52 #include "runtime/sweeper.hpp"
  53 #include "utilities/dtrace.hpp"
  54 #include "jvmci/jvmciRuntime.hpp"
  55 #include "jvmci/jvmciJavaClasses.hpp"
  56 
  57 JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter):
  58   _task(task),
  59   _system_dictionary_modification_counter(system_dictionary_modification_counter),
  60   _failure_reason(NULL),
  61   _retryable(true)
  62 {
  63   // Get Jvmti capabilities under lock to get consistent values.
  64   MutexLocker mu(JvmtiThreadState_lock);
  65   _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint() ? 1 : 0;
  66   _jvmti_can_access_local_variables     = JvmtiExport::can_access_local_variables() ? 1 : 0;
  67   _jvmti_can_post_on_exceptions         = JvmtiExport::can_post_on_exceptions() ? 1 : 0;
  68   _jvmti_can_pop_frame                  = JvmtiExport::can_pop_frame() ? 1 : 0;
  69 }
  70 
  71 bool JVMCIEnv::jvmti_state_changed() const {
  72   if (!jvmti_can_access_local_variables() &&
  73       JvmtiExport::can_access_local_variables()) {
  74     return true;
  75   }
  76   if (!jvmti_can_hotswap_or_post_breakpoint() &&
  77       JvmtiExport::can_hotswap_or_post_breakpoint()) {
  78     return true;
  79   }
  80   if (!jvmti_can_post_on_exceptions() &&
  81       JvmtiExport::can_post_on_exceptions()) {
  82     return true;
  83   }
  84   if (!jvmti_can_pop_frame() &&
  85       JvmtiExport::can_pop_frame()) {
  86     return true;
  87   }
  88   return false;
  89 }
  90 
  91 // ------------------------------------------------------------------
  92 // Note: the logic of this method should mirror the logic of
  93 // constantPoolOopDesc::verify_constant_pool_resolve.
  94 bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) {
  95   if (accessing_klass->is_objArray_klass()) {
  96     accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass();
  97   }
  98   if (!accessing_klass->is_instance_klass()) {
  99     return true;
 100   }
 101 
 102   if (resolved_klass->is_objArray_klass()) {
 103     // Find the element klass, if this is an array.
 104     resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass();
 105   }
 106   if (resolved_klass->is_instance_klass()) {
 107     Reflection::VerifyClassAccessResults result =
 108       Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true);


 416     ShouldNotReachHere();
 417   }
 418   return NULL;
 419 }
 420 
 421 
 422 // ------------------------------------------------------------------
 423 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
 424                                      int index, Bytecodes::Code bc,
 425                                      InstanceKlass* accessor) {
 426   ResourceMark rm;
 427   return get_method_by_index_impl(cpool, index, bc, accessor);
 428 }
 429 
 430 // ------------------------------------------------------------------
 431 // Check for changes to the system dictionary during compilation
 432 // class loads, evolution, breakpoints
 433 JVMCIEnv::CodeInstallResult JVMCIEnv::validate_compile_task_dependencies(Dependencies* dependencies, Handle compiled_code,
 434                                                                          JVMCIEnv* env, char** failure_detail) {
 435   // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
 436   if (env != NULL && env->jvmti_state_changed()) {
 437     *failure_detail = (char*) "Jvmti state change during compilation invalidated dependencies";

 438     return JVMCIEnv::dependencies_failed;
 439   }

 440 
 441   // Dependencies must be checked when the system dictionary changes
 442   // or if we don't know whether it has changed (i.e., env == NULL).
 443   bool counter_changed = env == NULL || env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
 444   CompileTask* task = env == NULL ? NULL : env->task();
 445   Dependencies::DepType result = dependencies->validate_dependencies(task, counter_changed, failure_detail);
 446   if (result == Dependencies::end_marker) {
 447     return JVMCIEnv::ok;
 448   }
 449 
 450   if (!Dependencies::is_klass_type(result) || counter_changed) {
 451     return JVMCIEnv::dependencies_failed;
 452   }
 453   // The dependencies were invalid at the time of installation
 454   // without any intervening modification of the system
 455   // dictionary.  That means they were invalidly constructed.
 456   return JVMCIEnv::dependencies_invalid;
 457 }
 458 
 459 // ------------------------------------------------------------------


< prev index next >