src/share/vm/prims/jvm.cpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/prims/jvm.cpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,4488 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "precompiled.hpp"
    1.29 +#include "classfile/classLoader.hpp"
    1.30 +#include "classfile/javaAssertions.hpp"
    1.31 +#include "classfile/javaClasses.hpp"
    1.32 +#include "classfile/symbolTable.hpp"
    1.33 +#include "classfile/systemDictionary.hpp"
    1.34 +#include "classfile/vmSymbols.hpp"
    1.35 +#include "gc_interface/collectedHeap.inline.hpp"
    1.36 +#include "interpreter/bytecode.hpp"
    1.37 +#include "memory/oopFactory.hpp"
    1.38 +#include "memory/universe.inline.hpp"
    1.39 +#include "oops/fieldStreams.hpp"
    1.40 +#include "oops/instanceKlass.hpp"
    1.41 +#include "oops/objArrayKlass.hpp"
    1.42 +#include "oops/method.hpp"
    1.43 +#include "prims/jvm.h"
    1.44 +#include "prims/jvm_misc.hpp"
    1.45 +#include "prims/jvmtiExport.hpp"
    1.46 +#include "prims/jvmtiThreadState.hpp"
    1.47 +#include "prims/nativeLookup.hpp"
    1.48 +#include "prims/privilegedStack.hpp"
    1.49 +#include "runtime/arguments.hpp"
    1.50 +#include "runtime/dtraceJSDT.hpp"
    1.51 +#include "runtime/handles.inline.hpp"
    1.52 +#include "runtime/init.hpp"
    1.53 +#include "runtime/interfaceSupport.hpp"
    1.54 +#include "runtime/java.hpp"
    1.55 +#include "runtime/javaCalls.hpp"
    1.56 +#include "runtime/jfieldIDWorkaround.hpp"
    1.57 +#include "runtime/os.hpp"
    1.58 +#include "runtime/perfData.hpp"
    1.59 +#include "runtime/reflection.hpp"
    1.60 +#include "runtime/vframe.hpp"
    1.61 +#include "runtime/vm_operations.hpp"
    1.62 +#include "services/attachListener.hpp"
    1.63 +#include "services/management.hpp"
    1.64 +#include "services/threadService.hpp"
    1.65 +#include "trace/tracing.hpp"
    1.66 +#include "utilities/copy.hpp"
    1.67 +#include "utilities/defaultStream.hpp"
    1.68 +#include "utilities/dtrace.hpp"
    1.69 +#include "utilities/events.hpp"
    1.70 +#include "utilities/histogram.hpp"
    1.71 +#include "utilities/top.hpp"
    1.72 +#include "utilities/utf8.hpp"
    1.73 +#ifdef TARGET_OS_FAMILY_linux
    1.74 +# include "jvm_linux.h"
    1.75 +#endif
    1.76 +#ifdef TARGET_OS_FAMILY_solaris
    1.77 +# include "jvm_solaris.h"
    1.78 +#endif
    1.79 +#ifdef TARGET_OS_FAMILY_windows
    1.80 +# include "jvm_windows.h"
    1.81 +#endif
    1.82 +#ifdef TARGET_OS_FAMILY_aix
    1.83 +# include "jvm_aix.h"
    1.84 +#endif
    1.85 +#ifdef TARGET_OS_FAMILY_bsd
    1.86 +# include "jvm_bsd.h"
    1.87 +#endif
    1.88 +
    1.89 +#include <errno.h>
    1.90 +
    1.91 +#ifndef USDT2
    1.92 +HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
    1.93 +HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
    1.94 +HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
    1.95 +#endif /* !USDT2 */
    1.96 +
    1.97 +/*
    1.98 +  NOTE about use of any ctor or function call that can trigger a safepoint/GC:
    1.99 +  such ctors and calls MUST NOT come between an oop declaration/init and its
   1.100 +  usage because if objects are move this may cause various memory stomps, bus
   1.101 +  errors and segfaults. Here is a cookbook for causing so called "naked oop
   1.102 +  failures":
   1.103 +
   1.104 +      JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
   1.105 +          JVMWrapper("JVM_GetClassDeclaredFields");
   1.106 +
   1.107 +          // Object address to be held directly in mirror & not visible to GC
   1.108 +          oop mirror = JNIHandles::resolve_non_null(ofClass);
   1.109 +
   1.110 +          // If this ctor can hit a safepoint, moving objects around, then
   1.111 +          ComplexConstructor foo;
   1.112 +
   1.113 +          // Boom! mirror may point to JUNK instead of the intended object
   1.114 +          (some dereference of mirror)
   1.115 +
   1.116 +          // Here's another call that may block for GC, making mirror stale
   1.117 +          MutexLocker ml(some_lock);
   1.118 +
   1.119 +          // And here's an initializer that can result in a stale oop
   1.120 +          // all in one step.
   1.121 +          oop o = call_that_can_throw_exception(TRAPS);
   1.122 +
   1.123 +
   1.124 +  The solution is to keep the oop declaration BELOW the ctor or function
   1.125 +  call that might cause a GC, do another resolve to reassign the oop, or
   1.126 +  consider use of a Handle instead of an oop so there is immunity from object
   1.127 +  motion. But note that the "QUICK" entries below do not have a handlemark
   1.128 +  and thus can only support use of handles passed in.
   1.129 +*/
   1.130 +
   1.131 +static void trace_class_resolution_impl(Klass* to_class, TRAPS) {
   1.132 +  ResourceMark rm;
   1.133 +  int line_number = -1;
   1.134 +  const char * source_file = NULL;
   1.135 +  const char * trace = "explicit";
   1.136 +  InstanceKlass* caller = NULL;
   1.137 +  JavaThread* jthread = JavaThread::current();
   1.138 +  if (jthread->has_last_Java_frame()) {
   1.139 +    vframeStream vfst(jthread);
   1.140 +
   1.141 +    // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames
   1.142 +    TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK);
   1.143 +    Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK);
   1.144 +    TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK);
   1.145 +    Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK);
   1.146 +
   1.147 +    Method* last_caller = NULL;
   1.148 +
   1.149 +    while (!vfst.at_end()) {
   1.150 +      Method* m = vfst.method();
   1.151 +      if (!vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass())&&
   1.152 +          !vfst.method()->method_holder()->is_subclass_of(access_controller_klass) &&
   1.153 +          !vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) {
   1.154 +        break;
   1.155 +      }
   1.156 +      last_caller = m;
   1.157 +      vfst.next();
   1.158 +    }
   1.159 +    // if this is called from Class.forName0 and that is called from Class.forName,
   1.160 +    // then print the caller of Class.forName.  If this is Class.loadClass, then print
   1.161 +    // that caller, otherwise keep quiet since this should be picked up elsewhere.
   1.162 +    bool found_it = false;
   1.163 +    if (!vfst.at_end() &&
   1.164 +        vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
   1.165 +        vfst.method()->name() == vmSymbols::forName0_name()) {
   1.166 +      vfst.next();
   1.167 +      if (!vfst.at_end() &&
   1.168 +          vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
   1.169 +          vfst.method()->name() == vmSymbols::forName_name()) {
   1.170 +        vfst.next();
   1.171 +        found_it = true;
   1.172 +      }
   1.173 +    } else if (last_caller != NULL &&
   1.174 +               last_caller->method_holder()->name() ==
   1.175 +               vmSymbols::java_lang_ClassLoader() &&
   1.176 +               (last_caller->name() == vmSymbols::loadClassInternal_name() ||
   1.177 +                last_caller->name() == vmSymbols::loadClass_name())) {
   1.178 +      found_it = true;
   1.179 +    } else if (!vfst.at_end()) {
   1.180 +      if (vfst.method()->is_native()) {
   1.181 +        // JNI call
   1.182 +        found_it = true;
   1.183 +      }
   1.184 +    }
   1.185 +    if (found_it && !vfst.at_end()) {
   1.186 +      // found the caller
   1.187 +      caller = vfst.method()->method_holder();
   1.188 +      line_number = vfst.method()->line_number_from_bci(vfst.bci());
   1.189 +      if (line_number == -1) {
   1.190 +        // show method name if it's a native method
   1.191 +        trace = vfst.method()->name_and_sig_as_C_string();
   1.192 +      }
   1.193 +      Symbol* s = caller->source_file_name();
   1.194 +      if (s != NULL) {
   1.195 +        source_file = s->as_C_string();
   1.196 +      }
   1.197 +    }
   1.198 +  }
   1.199 +  if (caller != NULL) {
   1.200 +    if (to_class != caller) {
   1.201 +      const char * from = caller->external_name();
   1.202 +      const char * to = to_class->external_name();
   1.203 +      // print in a single call to reduce interleaving between threads
   1.204 +      if (source_file != NULL) {
   1.205 +        tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace);
   1.206 +      } else {
   1.207 +        tty->print("RESOLVE %s %s (%s)\n", from, to, trace);
   1.208 +      }
   1.209 +    }
   1.210 +  }
   1.211 +}
   1.212 +
   1.213 +void trace_class_resolution(Klass* to_class) {
   1.214 +  EXCEPTION_MARK;
   1.215 +  trace_class_resolution_impl(to_class, THREAD);
   1.216 +  if (HAS_PENDING_EXCEPTION) {
   1.217 +    CLEAR_PENDING_EXCEPTION;
   1.218 +  }
   1.219 +}
   1.220 +
   1.221 +// Wrapper to trace JVM functions
   1.222 +
   1.223 +#ifdef ASSERT
   1.224 +  class JVMTraceWrapper : public StackObj {
   1.225 +   public:
   1.226 +    JVMTraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
   1.227 +      if (TraceJVMCalls) {
   1.228 +        va_list ap;
   1.229 +        va_start(ap, format);
   1.230 +        tty->print("JVM ");
   1.231 +        tty->vprint_cr(format, ap);
   1.232 +        va_end(ap);
   1.233 +      }
   1.234 +    }
   1.235 +  };
   1.236 +
   1.237 +  Histogram* JVMHistogram;
   1.238 +  volatile jint JVMHistogram_lock = 0;
   1.239 +
   1.240 +  class JVMHistogramElement : public HistogramElement {
   1.241 +    public:
   1.242 +     JVMHistogramElement(const char* name);
   1.243 +  };
   1.244 +
   1.245 +  JVMHistogramElement::JVMHistogramElement(const char* elementName) {
   1.246 +    _name = elementName;
   1.247 +    uintx count = 0;
   1.248 +
   1.249 +    while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) {
   1.250 +      while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) {
   1.251 +        count +=1;
   1.252 +        if ( (WarnOnStalledSpinLock > 0)
   1.253 +          && (count % WarnOnStalledSpinLock == 0)) {
   1.254 +          warning("JVMHistogram_lock seems to be stalled");
   1.255 +        }
   1.256 +      }
   1.257 +     }
   1.258 +
   1.259 +    if(JVMHistogram == NULL)
   1.260 +      JVMHistogram = new Histogram("JVM Call Counts",100);
   1.261 +
   1.262 +    JVMHistogram->add_element(this);
   1.263 +    Atomic::dec(&JVMHistogram_lock);
   1.264 +  }
   1.265 +
   1.266 +  #define JVMCountWrapper(arg) \
   1.267 +      static JVMHistogramElement* e = new JVMHistogramElement(arg); \
   1.268 +      if (e != NULL) e->increment_count();  // Due to bug in VC++, we need a NULL check here eventhough it should never happen!
   1.269 +
   1.270 +  #define JVMWrapper(arg1)                    JVMCountWrapper(arg1); JVMTraceWrapper(arg1)
   1.271 +  #define JVMWrapper2(arg1, arg2)             JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2)
   1.272 +  #define JVMWrapper3(arg1, arg2, arg3)       JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3)
   1.273 +  #define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4)
   1.274 +#else
   1.275 +  #define JVMWrapper(arg1)
   1.276 +  #define JVMWrapper2(arg1, arg2)
   1.277 +  #define JVMWrapper3(arg1, arg2, arg3)
   1.278 +  #define JVMWrapper4(arg1, arg2, arg3, arg4)
   1.279 +#endif
   1.280 +
   1.281 +
   1.282 +// Interface version /////////////////////////////////////////////////////////////////////
   1.283 +
   1.284 +
   1.285 +JVM_LEAF(jint, JVM_GetInterfaceVersion())
   1.286 +  return JVM_INTERFACE_VERSION;
   1.287 +JVM_END
   1.288 +
   1.289 +
   1.290 +// java.lang.System //////////////////////////////////////////////////////////////////////
   1.291 +
   1.292 +
   1.293 +JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
   1.294 +  JVMWrapper("JVM_CurrentTimeMillis");
   1.295 +  return os::javaTimeMillis();
   1.296 +JVM_END
   1.297 +
   1.298 +JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
   1.299 +  JVMWrapper("JVM_NanoTime");
   1.300 +  return os::javaTimeNanos();
   1.301 +JVM_END
   1.302 +
   1.303 +
   1.304 +JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
   1.305 +                               jobject dst, jint dst_pos, jint length))
   1.306 +  JVMWrapper("JVM_ArrayCopy");
   1.307 +  // Check if we have null pointers
   1.308 +  if (src == NULL || dst == NULL) {
   1.309 +    THROW(vmSymbols::java_lang_NullPointerException());
   1.310 +  }
   1.311 +  arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
   1.312 +  arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
   1.313 +  assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
   1.314 +  assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
   1.315 +  // Do copy
   1.316 +  s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread);
   1.317 +JVM_END
   1.318 +
   1.319 +
   1.320 +static void set_property(Handle props, const char* key, const char* value, TRAPS) {
   1.321 +  JavaValue r(T_OBJECT);
   1.322 +  // public synchronized Object put(Object key, Object value);
   1.323 +  HandleMark hm(THREAD);
   1.324 +  Handle key_str    = java_lang_String::create_from_platform_dependent_str(key, CHECK);
   1.325 +  Handle value_str  = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
   1.326 +  JavaCalls::call_virtual(&r,
   1.327 +                          props,
   1.328 +                          KlassHandle(THREAD, SystemDictionary::Properties_klass()),
   1.329 +                          vmSymbols::put_name(),
   1.330 +                          vmSymbols::object_object_object_signature(),
   1.331 +                          key_str,
   1.332 +                          value_str,
   1.333 +                          THREAD);
   1.334 +}
   1.335 +
   1.336 +
   1.337 +#define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties));
   1.338 +
   1.339 +
   1.340 +JVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties))
   1.341 +  JVMWrapper("JVM_InitProperties");
   1.342 +  ResourceMark rm;
   1.343 +
   1.344 +  Handle props(THREAD, JNIHandles::resolve_non_null(properties));
   1.345 +
   1.346 +  // System property list includes both user set via -D option and
   1.347 +  // jvm system specific properties.
   1.348 +  for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
   1.349 +    PUTPROP(props, p->key(), p->value());
   1.350 +  }
   1.351 +
   1.352 +  // Convert the -XX:MaxDirectMemorySize= command line flag
   1.353 +  // to the sun.nio.MaxDirectMemorySize property.
   1.354 +  // Do this after setting user properties to prevent people
   1.355 +  // from setting the value with a -D option, as requested.
   1.356 +  {
   1.357 +    if (FLAG_IS_DEFAULT(MaxDirectMemorySize)) {
   1.358 +      PUTPROP(props, "sun.nio.MaxDirectMemorySize", "-1");
   1.359 +    } else {
   1.360 +      char as_chars[256];
   1.361 +      jio_snprintf(as_chars, sizeof(as_chars), UINTX_FORMAT, MaxDirectMemorySize);
   1.362 +      PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars);
   1.363 +    }
   1.364 +  }
   1.365 +
   1.366 +  // JVM monitoring and management support
   1.367 +  // Add the sun.management.compiler property for the compiler's name
   1.368 +  {
   1.369 +#undef CSIZE
   1.370 +#if defined(_LP64) || defined(_WIN64)
   1.371 +  #define CSIZE "64-Bit "
   1.372 +#else
   1.373 +  #define CSIZE
   1.374 +#endif // 64bit
   1.375 +
   1.376 +#ifdef TIERED
   1.377 +    const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers";
   1.378 +#else
   1.379 +#if defined(COMPILER1)
   1.380 +    const char* compiler_name = "HotSpot " CSIZE "Client Compiler";
   1.381 +#elif defined(COMPILER2)
   1.382 +    const char* compiler_name = "HotSpot " CSIZE "Server Compiler";
   1.383 +#else
   1.384 +    const char* compiler_name = "";
   1.385 +#endif // compilers
   1.386 +#endif // TIERED
   1.387 +
   1.388 +    if (*compiler_name != '\0' &&
   1.389 +        (Arguments::mode() != Arguments::_int)) {
   1.390 +      PUTPROP(props, "sun.management.compiler", compiler_name);
   1.391 +    }
   1.392 +  }
   1.393 +
   1.394 +  return properties;
   1.395 +JVM_END
   1.396 +
   1.397 +
   1.398 +/*
   1.399 + * Return the temporary directory that the VM uses for the attach
   1.400 + * and perf data files.
   1.401 + *
   1.402 + * It is important that this directory is well-known and the
   1.403 + * same for all VM instances. It cannot be affected by configuration
   1.404 + * variables such as java.io.tmpdir.
   1.405 + */
   1.406 +JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
   1.407 +  JVMWrapper("JVM_GetTemporaryDirectory");
   1.408 +  HandleMark hm(THREAD);
   1.409 +  const char* temp_dir = os::get_temp_directory();
   1.410 +  Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
   1.411 +  return (jstring) JNIHandles::make_local(env, h());
   1.412 +JVM_END
   1.413 +
   1.414 +
   1.415 +// java.lang.Runtime /////////////////////////////////////////////////////////////////////////
   1.416 +
   1.417 +extern volatile jint vm_created;
   1.418 +
   1.419 +JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
   1.420 +  if (vm_created != 0 && (code == 0)) {
   1.421 +    // The VM is about to exit. We call back into Java to check whether finalizers should be run
   1.422 +    Universe::run_finalizers_on_exit();
   1.423 +  }
   1.424 +  before_exit(thread);
   1.425 +  vm_exit(code);
   1.426 +JVM_END
   1.427 +
   1.428 +
   1.429 +JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
   1.430 +  before_exit(thread);
   1.431 +  vm_exit(code);
   1.432 +JVM_END
   1.433 +
   1.434 +
   1.435 +JVM_LEAF(void, JVM_OnExit(void (*func)(void)))
   1.436 +  register_on_exit_function(func);
   1.437 +JVM_END
   1.438 +
   1.439 +
   1.440 +JVM_ENTRY_NO_ENV(void, JVM_GC(void))
   1.441 +  JVMWrapper("JVM_GC");
   1.442 +  if (!DisableExplicitGC) {
   1.443 +    Universe::heap()->collect(GCCause::_java_lang_system_gc);
   1.444 +  }
   1.445 +JVM_END
   1.446 +
   1.447 +
   1.448 +JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))
   1.449 +  JVMWrapper("JVM_MaxObjectInspectionAge");
   1.450 +  return Universe::heap()->millis_since_last_gc();
   1.451 +JVM_END
   1.452 +
   1.453 +
   1.454 +JVM_LEAF(void, JVM_TraceInstructions(jboolean on))
   1.455 +  if (PrintJVMWarnings) warning("JVM_TraceInstructions not supported");
   1.456 +JVM_END
   1.457 +
   1.458 +
   1.459 +JVM_LEAF(void, JVM_TraceMethodCalls(jboolean on))
   1.460 +  if (PrintJVMWarnings) warning("JVM_TraceMethodCalls not supported");
   1.461 +JVM_END
   1.462 +
   1.463 +static inline jlong convert_size_t_to_jlong(size_t val) {
   1.464 +  // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
   1.465 +  NOT_LP64 (return (jlong)val;)
   1.466 +  LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);)
   1.467 +}
   1.468 +
   1.469 +JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void))
   1.470 +  JVMWrapper("JVM_TotalMemory");
   1.471 +  size_t n = Universe::heap()->capacity();
   1.472 +  return convert_size_t_to_jlong(n);
   1.473 +JVM_END
   1.474 +
   1.475 +
   1.476 +JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
   1.477 +  JVMWrapper("JVM_FreeMemory");
   1.478 +  CollectedHeap* ch = Universe::heap();
   1.479 +  size_t n;
   1.480 +  {
   1.481 +     MutexLocker x(Heap_lock);
   1.482 +     n = ch->capacity() - ch->used();
   1.483 +  }
   1.484 +  return convert_size_t_to_jlong(n);
   1.485 +JVM_END
   1.486 +
   1.487 +
   1.488 +JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
   1.489 +  JVMWrapper("JVM_MaxMemory");
   1.490 +  size_t n = Universe::heap()->max_capacity();
   1.491 +  return convert_size_t_to_jlong(n);
   1.492 +JVM_END
   1.493 +
   1.494 +
   1.495 +JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
   1.496 +  JVMWrapper("JVM_ActiveProcessorCount");
   1.497 +  return os::active_processor_count();
   1.498 +JVM_END
   1.499 +
   1.500 +
   1.501 +
   1.502 +// java.lang.Throwable //////////////////////////////////////////////////////
   1.503 +
   1.504 +
   1.505 +JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
   1.506 +  JVMWrapper("JVM_FillInStackTrace");
   1.507 +  Handle exception(thread, JNIHandles::resolve_non_null(receiver));
   1.508 +  java_lang_Throwable::fill_in_stack_trace(exception);
   1.509 +JVM_END
   1.510 +
   1.511 +
   1.512 +JVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable))
   1.513 +  JVMWrapper("JVM_GetStackTraceDepth");
   1.514 +  oop exception = JNIHandles::resolve(throwable);
   1.515 +  return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
   1.516 +JVM_END
   1.517 +
   1.518 +
   1.519 +JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
   1.520 +  JVMWrapper("JVM_GetStackTraceElement");
   1.521 +  JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
   1.522 +  oop exception = JNIHandles::resolve(throwable);
   1.523 +  oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
   1.524 +  return JNIHandles::make_local(env, element);
   1.525 +JVM_END
   1.526 +
   1.527 +
   1.528 +// java.lang.Object ///////////////////////////////////////////////
   1.529 +
   1.530 +
   1.531 +JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
   1.532 +  JVMWrapper("JVM_IHashCode");
   1.533 +  // as implemented in the classic virtual machine; return 0 if object is NULL
   1.534 +  return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
   1.535 +JVM_END
   1.536 +
   1.537 +
   1.538 +JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
   1.539 +  JVMWrapper("JVM_MonitorWait");
   1.540 +  Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
   1.541 +  JavaThreadInObjectWaitState jtiows(thread, ms != 0);
   1.542 +  if (JvmtiExport::should_post_monitor_wait()) {
   1.543 +    JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
   1.544 +
   1.545 +    // The current thread already owns the monitor and it has not yet
   1.546 +    // been added to the wait queue so the current thread cannot be
   1.547 +    // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
   1.548 +    // event handler cannot accidentally consume an unpark() meant for
   1.549 +    // the ParkEvent associated with this ObjectMonitor.
   1.550 +  }
   1.551 +  ObjectSynchronizer::wait(obj, ms, CHECK);
   1.552 +JVM_END
   1.553 +
   1.554 +
   1.555 +JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
   1.556 +  JVMWrapper("JVM_MonitorNotify");
   1.557 +  Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
   1.558 +  ObjectSynchronizer::notify(obj, CHECK);
   1.559 +JVM_END
   1.560 +
   1.561 +
   1.562 +JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
   1.563 +  JVMWrapper("JVM_MonitorNotifyAll");
   1.564 +  Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
   1.565 +  ObjectSynchronizer::notifyall(obj, CHECK);
   1.566 +JVM_END
   1.567 +
   1.568 +
   1.569 +JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
   1.570 +  JVMWrapper("JVM_Clone");
   1.571 +  Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
   1.572 +  const KlassHandle klass (THREAD, obj->klass());
   1.573 +  JvmtiVMObjectAllocEventCollector oam;
   1.574 +
   1.575 +#ifdef ASSERT
   1.576 +  // Just checking that the cloneable flag is set correct
   1.577 +  if (obj->is_array()) {
   1.578 +    guarantee(klass->is_cloneable(), "all arrays are cloneable");
   1.579 +  } else {
   1.580 +    guarantee(obj->is_instance(), "should be instanceOop");
   1.581 +    bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
   1.582 +    guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
   1.583 +  }
   1.584 +#endif
   1.585 +
   1.586 +  // Check if class of obj supports the Cloneable interface.
   1.587 +  // All arrays are considered to be cloneable (See JLS 20.1.5)
   1.588 +  if (!klass->is_cloneable()) {
   1.589 +    ResourceMark rm(THREAD);
   1.590 +    THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
   1.591 +  }
   1.592 +
   1.593 +  // Make shallow object copy
   1.594 +  const int size = obj->size();
   1.595 +  oop new_obj = NULL;
   1.596 +  if (obj->is_array()) {
   1.597 +    const int length = ((arrayOop)obj())->length();
   1.598 +    new_obj = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
   1.599 +  } else {
   1.600 +    new_obj = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
   1.601 +  }
   1.602 +  // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
   1.603 +  // is modifying a reference field in the clonee, a non-oop-atomic copy might
   1.604 +  // be suspended in the middle of copying the pointer and end up with parts
   1.605 +  // of two different pointers in the field.  Subsequent dereferences will crash.
   1.606 +  // 4846409: an oop-copy of objects with long or double fields or arrays of same
   1.607 +  // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
   1.608 +  // of oops.  We know objects are aligned on a minimum of an jlong boundary.
   1.609 +  // The same is true of StubRoutines::object_copy and the various oop_copy
   1.610 +  // variants, and of the code generated by the inline_native_clone intrinsic.
   1.611 +  assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
   1.612 +  Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj,
   1.613 +                               (size_t)align_object_size(size) / HeapWordsPerLong);
   1.614 +  // Clear the header
   1.615 +  new_obj->init_mark();
   1.616 +
   1.617 +  // Store check (mark entire object and let gc sort it out)
   1.618 +  BarrierSet* bs = Universe::heap()->barrier_set();
   1.619 +  assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
   1.620 +  bs->write_region(MemRegion((HeapWord*)new_obj, size));
   1.621 +
   1.622 +  // Caution: this involves a java upcall, so the clone should be
   1.623 +  // "gc-robust" by this stage.
   1.624 +  if (klass->has_finalizer()) {
   1.625 +    assert(obj->is_instance(), "should be instanceOop");
   1.626 +    new_obj = InstanceKlass::register_finalizer(instanceOop(new_obj), CHECK_NULL);
   1.627 +  }
   1.628 +
   1.629 +  return JNIHandles::make_local(env, oop(new_obj));
   1.630 +JVM_END
   1.631 +
   1.632 +// java.lang.Compiler ////////////////////////////////////////////////////
   1.633 +
   1.634 +// The initial cuts of the HotSpot VM will not support JITs, and all existing
   1.635 +// JITs would need extensive changes to work with HotSpot.  The JIT-related JVM
   1.636 +// functions are all silently ignored unless JVM warnings are printed.
   1.637 +
   1.638 +JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
   1.639 +  if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
   1.640 +JVM_END
   1.641 +
   1.642 +
   1.643 +JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
   1.644 +  if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
   1.645 +  return JNI_FALSE;
   1.646 +JVM_END
   1.647 +
   1.648 +
   1.649 +JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))
   1.650 +  if (PrintJVMWarnings) warning("JVM_CompileClass not supported");
   1.651 +  return JNI_FALSE;
   1.652 +JVM_END
   1.653 +
   1.654 +
   1.655 +JVM_LEAF(jboolean, JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname))
   1.656 +  if (PrintJVMWarnings) warning("JVM_CompileClasses not supported");
   1.657 +  return JNI_FALSE;
   1.658 +JVM_END
   1.659 +
   1.660 +
   1.661 +JVM_LEAF(jobject, JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg))
   1.662 +  if (PrintJVMWarnings) warning("JVM_CompilerCommand not supported");
   1.663 +  return NULL;
   1.664 +JVM_END
   1.665 +
   1.666 +
   1.667 +JVM_LEAF(void, JVM_EnableCompiler(JNIEnv *env, jclass compCls))
   1.668 +  if (PrintJVMWarnings) warning("JVM_EnableCompiler not supported");
   1.669 +JVM_END
   1.670 +
   1.671 +
   1.672 +JVM_LEAF(void, JVM_DisableCompiler(JNIEnv *env, jclass compCls))
   1.673 +  if (PrintJVMWarnings) warning("JVM_DisableCompiler not supported");
   1.674 +JVM_END
   1.675 +
   1.676 +
   1.677 +
   1.678 +// Error message support //////////////////////////////////////////////////////
   1.679 +
   1.680 +JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
   1.681 +  JVMWrapper("JVM_GetLastErrorString");
   1.682 +  return (jint)os::lasterror(buf, len);
   1.683 +JVM_END
   1.684 +
   1.685 +
   1.686 +// java.io.File ///////////////////////////////////////////////////////////////
   1.687 +
   1.688 +JVM_LEAF(char*, JVM_NativePath(char* path))
   1.689 +  JVMWrapper2("JVM_NativePath (%s)", path);
   1.690 +  return os::native_path(path);
   1.691 +JVM_END
   1.692 +
   1.693 +
   1.694 +// Misc. class handling ///////////////////////////////////////////////////////////
   1.695 +
   1.696 +
   1.697 +JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
   1.698 +  JVMWrapper("JVM_GetCallerClass");
   1.699 +
   1.700 +  // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
   1.701 +  // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
   1.702 +  // temporarily for existing code to use until a replacement API is defined.
   1.703 +  if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
   1.704 +    Klass* k = thread->security_get_caller_class(depth);
   1.705 +    return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
   1.706 +  }
   1.707 +
   1.708 +  // Getting the class of the caller frame.
   1.709 +  //
   1.710 +  // The call stack at this point looks something like this:
   1.711 +  //
   1.712 +  // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
   1.713 +  // [1] [ @CallerSensitive API.method                                   ]
   1.714 +  // [.] [ (skipped intermediate frames)                                 ]
   1.715 +  // [n] [ caller                                                        ]
   1.716 +  vframeStream vfst(thread);
   1.717 +  // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass
   1.718 +  for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) {
   1.719 +    Method* m = vfst.method();
   1.720 +    assert(m != NULL, "sanity");
   1.721 +    switch (n) {
   1.722 +    case 0:
   1.723 +      // This must only be called from Reflection.getCallerClass
   1.724 +      if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) {
   1.725 +        THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass");
   1.726 +      }
   1.727 +      // fall-through
   1.728 +    case 1:
   1.729 +      // Frame 0 and 1 must be caller sensitive.
   1.730 +      if (!m->caller_sensitive()) {
   1.731 +        THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n));
   1.732 +      }
   1.733 +      break;
   1.734 +    default:
   1.735 +      if (!m->is_ignored_by_security_stack_walk()) {
   1.736 +        // We have reached the desired frame; return the holder class.
   1.737 +        return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror());
   1.738 +      }
   1.739 +      break;
   1.740 +    }
   1.741 +  }
   1.742 +  return NULL;
   1.743 +JVM_END
   1.744 +
   1.745 +
   1.746 +JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
   1.747 +  JVMWrapper("JVM_FindPrimitiveClass");
   1.748 +  oop mirror = NULL;
   1.749 +  BasicType t = name2type(utf);
   1.750 +  if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
   1.751 +    mirror = Universe::java_mirror(t);
   1.752 +  }
   1.753 +  if (mirror == NULL) {
   1.754 +    THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
   1.755 +  } else {
   1.756 +    return (jclass) JNIHandles::make_local(env, mirror);
   1.757 +  }
   1.758 +JVM_END
   1.759 +
   1.760 +
   1.761 +JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
   1.762 +  JVMWrapper("JVM_ResolveClass");
   1.763 +  if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented");
   1.764 +JVM_END
   1.765 +
   1.766 +
   1.767 +// Returns a class loaded by the bootstrap class loader; or null
   1.768 +// if not found.  ClassNotFoundException is not thrown.
   1.769 +//
   1.770 +// Rationale behind JVM_FindClassFromBootLoader
   1.771 +// a> JVM_FindClassFromClassLoader was never exported in the export tables.
   1.772 +// b> because of (a) java.dll has a direct dependecy on the  unexported
   1.773 +//    private symbol "_JVM_FindClassFromClassLoader@20".
   1.774 +// c> the launcher cannot use the private symbol as it dynamically opens
   1.775 +//    the entry point, so if something changes, the launcher will fail
   1.776 +//    unexpectedly at runtime, it is safest for the launcher to dlopen a
   1.777 +//    stable exported interface.
   1.778 +// d> re-exporting JVM_FindClassFromClassLoader as public, will cause its
   1.779 +//    signature to change from _JVM_FindClassFromClassLoader@20 to
   1.780 +//    JVM_FindClassFromClassLoader and will not be backward compatible
   1.781 +//    with older JDKs.
   1.782 +// Thus a public/stable exported entry point is the right solution,
   1.783 +// public here means public in linker semantics, and is exported only
   1.784 +// to the JDK, and is not intended to be a public API.
   1.785 +
   1.786 +JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
   1.787 +                                              const char* name))
   1.788 +  JVMWrapper2("JVM_FindClassFromBootLoader %s", name);
   1.789 +
   1.790 +  // Java libraries should ensure that name is never null...
   1.791 +  if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
   1.792 +    // It's impossible to create this class;  the name cannot fit
   1.793 +    // into the constant pool.
   1.794 +    return NULL;
   1.795 +  }
   1.796 +
   1.797 +  TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
   1.798 +  Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL);
   1.799 +  if (k == NULL) {
   1.800 +    return NULL;
   1.801 +  }
   1.802 +
   1.803 +  if (TraceClassResolution) {
   1.804 +    trace_class_resolution(k);
   1.805 +  }
   1.806 +  return (jclass) JNIHandles::make_local(env, k->java_mirror());
   1.807 +JVM_END
   1.808 +
   1.809 +// Not used; JVM_FindClassFromCaller replaces this.
   1.810 +JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
   1.811 +                                               jboolean init, jobject loader,
   1.812 +                                               jboolean throwError))
   1.813 +  JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name,
   1.814 +               throwError ? "error" : "exception");
   1.815 +  // Java libraries should ensure that name is never null...
   1.816 +  if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
   1.817 +    // It's impossible to create this class;  the name cannot fit
   1.818 +    // into the constant pool.
   1.819 +    if (throwError) {
   1.820 +      THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
   1.821 +    } else {
   1.822 +      THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
   1.823 +    }
   1.824 +  }
   1.825 +  TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
   1.826 +  Handle h_loader(THREAD, JNIHandles::resolve(loader));
   1.827 +  jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   1.828 +                                               Handle(), throwError, THREAD);
   1.829 +
   1.830 +  if (TraceClassResolution && result != NULL) {
   1.831 +    trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   1.832 +  }
   1.833 +  return result;
   1.834 +JVM_END
   1.835 +
   1.836 +// Find a class with this name in this loader, using the caller's protection domain.
   1.837 +JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name,
   1.838 +                                          jboolean init, jobject loader,
   1.839 +                                          jclass caller))
   1.840 +  JVMWrapper2("JVM_FindClassFromCaller %s throws ClassNotFoundException", name);
   1.841 +  // Java libraries should ensure that name is never null...
   1.842 +  if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
   1.843 +    // It's impossible to create this class;  the name cannot fit
   1.844 +    // into the constant pool.
   1.845 +    THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
   1.846 +  }
   1.847 +
   1.848 +  TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
   1.849 +
   1.850 +  oop loader_oop = JNIHandles::resolve(loader);
   1.851 +  oop from_class = JNIHandles::resolve(caller);
   1.852 +  oop protection_domain = NULL;
   1.853 +  // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get
   1.854 +  // NPE. Put it in another way, the bootstrap class loader has all permission and
   1.855 +  // thus no checkPackageAccess equivalence in the VM class loader.
   1.856 +  // The caller is also passed as NULL by the java code if there is no security
   1.857 +  // manager to avoid the performance cost of getting the calling class.
   1.858 +  if (from_class != NULL && loader_oop != NULL) {
   1.859 +    protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
   1.860 +  }
   1.861 +
   1.862 +  Handle h_loader(THREAD, loader_oop);
   1.863 +  Handle h_prot(THREAD, protection_domain);
   1.864 +  jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   1.865 +                                               h_prot, false, THREAD);
   1.866 +
   1.867 +  if (TraceClassResolution && result != NULL) {
   1.868 +    trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
   1.869 +  }
   1.870 +  return result;
   1.871 +JVM_END
   1.872 +
   1.873 +JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
   1.874 +                                         jboolean init, jclass from))
   1.875 +  JVMWrapper2("JVM_FindClassFromClass %s", name);
   1.876 +  if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
   1.877 +    // It's impossible to create this class;  the name cannot fit
   1.878 +    // into the constant pool.
   1.879 +    THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
   1.880 +  }
   1.881 +  TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
   1.882 +  oop from_class_oop = JNIHandles::resolve(from);
   1.883 +  Klass* from_class = (from_class_oop == NULL)
   1.884 +                           ? (Klass*)NULL
   1.885 +                           : java_lang_Class::as_Klass(from_class_oop);
   1.886 +  oop class_loader = NULL;
   1.887 +  oop protection_domain = NULL;
   1.888 +  if (from_class != NULL) {
   1.889 +    class_loader = from_class->class_loader();
   1.890 +    protection_domain = from_class->protection_domain();
   1.891 +  }
   1.892 +  Handle h_loader(THREAD, class_loader);
   1.893 +  Handle h_prot  (THREAD, protection_domain);
   1.894 +  jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
   1.895 +                                               h_prot, true, thread);
   1.896 +
   1.897 +  if (TraceClassResolution && result != NULL) {
   1.898 +    // this function is generally only used for class loading during verification.
   1.899 +    ResourceMark rm;
   1.900 +    oop from_mirror = JNIHandles::resolve_non_null(from);
   1.901 +    Klass* from_class = java_lang_Class::as_Klass(from_mirror);
   1.902 +    const char * from_name = from_class->external_name();
   1.903 +
   1.904 +    oop mirror = JNIHandles::resolve_non_null(result);
   1.905 +    Klass* to_class = java_lang_Class::as_Klass(mirror);
   1.906 +    const char * to = to_class->external_name();
   1.907 +    tty->print("RESOLVE %s %s (verification)\n", from_name, to);
   1.908 +  }
   1.909 +
   1.910 +  return result;
   1.911 +JVM_END
   1.912 +
   1.913 +static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) {
   1.914 +  if (loader.is_null()) {
   1.915 +    return;
   1.916 +  }
   1.917 +
   1.918 +  // check whether the current caller thread holds the lock or not.
   1.919 +  // If not, increment the corresponding counter
   1.920 +  if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) !=
   1.921 +      ObjectSynchronizer::owner_self) {
   1.922 +    counter->inc();
   1.923 +  }
   1.924 +}
   1.925 +
   1.926 +// common code for JVM_DefineClass() and JVM_DefineClassWithSource()
   1.927 +// and JVM_DefineClassWithSourceCond()
   1.928 +static jclass jvm_define_class_common(JNIEnv *env, const char *name,
   1.929 +                                      jobject loader, const jbyte *buf,
   1.930 +                                      jsize len, jobject pd, const char *source,
   1.931 +                                      jboolean verify, TRAPS) {
   1.932 +  if (source == NULL)  source = "__JVM_DefineClass__";
   1.933 +
   1.934 +  assert(THREAD->is_Java_thread(), "must be a JavaThread");
   1.935 +  JavaThread* jt = (JavaThread*) THREAD;
   1.936 +
   1.937 +  PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(),
   1.938 +                             ClassLoader::perf_define_appclass_selftime(),
   1.939 +                             ClassLoader::perf_define_appclasses(),
   1.940 +                             jt->get_thread_stat()->perf_recursion_counts_addr(),
   1.941 +                             jt->get_thread_stat()->perf_timers_addr(),
   1.942 +                             PerfClassTraceTime::DEFINE_CLASS);
   1.943 +
   1.944 +  if (UsePerfData) {
   1.945 +    ClassLoader::perf_app_classfile_bytes_read()->inc(len);
   1.946 +  }
   1.947 +
   1.948 +  // Since exceptions can be thrown, class initialization can take place
   1.949 +  // if name is NULL no check for class name in .class stream has to be made.
   1.950 +  TempNewSymbol class_name = NULL;
   1.951 +  if (name != NULL) {
   1.952 +    const int str_len = (int)strlen(name);
   1.953 +    if (str_len > Symbol::max_length()) {
   1.954 +      // It's impossible to create this class;  the name cannot fit
   1.955 +      // into the constant pool.
   1.956 +      THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
   1.957 +    }
   1.958 +    class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
   1.959 +  }
   1.960 +
   1.961 +  ResourceMark rm(THREAD);
   1.962 +  ClassFileStream st((u1*) buf, len, (char *)source);
   1.963 +  Handle class_loader (THREAD, JNIHandles::resolve(loader));
   1.964 +  if (UsePerfData) {
   1.965 +    is_lock_held_by_thread(class_loader,
   1.966 +                           ClassLoader::sync_JVMDefineClassLockFreeCounter(),
   1.967 +                           THREAD);
   1.968 +  }
   1.969 +  Handle protection_domain (THREAD, JNIHandles::resolve(pd));
   1.970 +  Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
   1.971 +                                                     protection_domain, &st,
   1.972 +                                                     verify != 0,
   1.973 +                                                     CHECK_NULL);
   1.974 +
   1.975 +  if (TraceClassResolution && k != NULL) {
   1.976 +    trace_class_resolution(k);
   1.977 +  }
   1.978 +
   1.979 +  return (jclass) JNIHandles::make_local(env, k->java_mirror());
   1.980 +}
   1.981 +
   1.982 +
   1.983 +JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
   1.984 +  JVMWrapper2("JVM_DefineClass %s", name);
   1.985 +
   1.986 +  return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD);
   1.987 +JVM_END
   1.988 +
   1.989 +
   1.990 +JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
   1.991 +  JVMWrapper2("JVM_DefineClassWithSource %s", name);
   1.992 +
   1.993 +  return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD);
   1.994 +JVM_END
   1.995 +
   1.996 +JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
   1.997 +                                                jobject loader, const jbyte *buf,
   1.998 +                                                jsize len, jobject pd,
   1.999 +                                                const char *source, jboolean verify))
  1.1000 +  JVMWrapper2("JVM_DefineClassWithSourceCond %s", name);
  1.1001 +
  1.1002 +  return jvm_define_class_common(env, name, loader, buf, len, pd, source, verify, THREAD);
  1.1003 +JVM_END
  1.1004 +
  1.1005 +JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
  1.1006 +  JVMWrapper("JVM_FindLoadedClass");
  1.1007 +  ResourceMark rm(THREAD);
  1.1008 +
  1.1009 +  Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
  1.1010 +  Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
  1.1011 +
  1.1012 +  const char* str   = java_lang_String::as_utf8_string(string());
  1.1013 +  // Sanity check, don't expect null
  1.1014 +  if (str == NULL) return NULL;
  1.1015 +
  1.1016 +  const int str_len = (int)strlen(str);
  1.1017 +  if (str_len > Symbol::max_length()) {
  1.1018 +    // It's impossible to create this class;  the name cannot fit
  1.1019 +    // into the constant pool.
  1.1020 +    return NULL;
  1.1021 +  }
  1.1022 +  TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
  1.1023 +
  1.1024 +  // Security Note:
  1.1025 +  //   The Java level wrapper will perform the necessary security check allowing
  1.1026 +  //   us to pass the NULL as the initiating class loader.
  1.1027 +  Handle h_loader(THREAD, JNIHandles::resolve(loader));
  1.1028 +  if (UsePerfData) {
  1.1029 +    is_lock_held_by_thread(h_loader,
  1.1030 +                           ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
  1.1031 +                           THREAD);
  1.1032 +  }
  1.1033 +
  1.1034 +  Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
  1.1035 +                                                              h_loader,
  1.1036 +                                                              Handle(),
  1.1037 +                                                              CHECK_NULL);
  1.1038 +
  1.1039 +  return (k == NULL) ? NULL :
  1.1040 +            (jclass) JNIHandles::make_local(env, k->java_mirror());
  1.1041 +JVM_END
  1.1042 +
  1.1043 +
  1.1044 +// Reflection support //////////////////////////////////////////////////////////////////////////////
  1.1045 +
  1.1046 +JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls))
  1.1047 +  assert (cls != NULL, "illegal class");
  1.1048 +  JVMWrapper("JVM_GetClassName");
  1.1049 +  JvmtiVMObjectAllocEventCollector oam;
  1.1050 +  ResourceMark rm(THREAD);
  1.1051 +  const char* name;
  1.1052 +  if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
  1.1053 +    name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls)));
  1.1054 +  } else {
  1.1055 +    // Consider caching interned string in Klass
  1.1056 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
  1.1057 +    assert(k->is_klass(), "just checking");
  1.1058 +    name = k->external_name();
  1.1059 +  }
  1.1060 +  oop result = StringTable::intern((char*) name, CHECK_NULL);
  1.1061 +  return (jstring) JNIHandles::make_local(env, result);
  1.1062 +JVM_END
  1.1063 +
  1.1064 +
  1.1065 +JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
  1.1066 +  JVMWrapper("JVM_GetClassInterfaces");
  1.1067 +  JvmtiVMObjectAllocEventCollector oam;
  1.1068 +  oop mirror = JNIHandles::resolve_non_null(cls);
  1.1069 +
  1.1070 +  // Special handling for primitive objects
  1.1071 +  if (java_lang_Class::is_primitive(mirror)) {
  1.1072 +    // Primitive objects does not have any interfaces
  1.1073 +    objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
  1.1074 +    return (jobjectArray) JNIHandles::make_local(env, r);
  1.1075 +  }
  1.1076 +
  1.1077 +  KlassHandle klass(thread, java_lang_Class::as_Klass(mirror));
  1.1078 +  // Figure size of result array
  1.1079 +  int size;
  1.1080 +  if (klass->oop_is_instance()) {
  1.1081 +    size = InstanceKlass::cast(klass())->local_interfaces()->length();
  1.1082 +  } else {
  1.1083 +    assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass");
  1.1084 +    size = 2;
  1.1085 +  }
  1.1086 +
  1.1087 +  // Allocate result array
  1.1088 +  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL);
  1.1089 +  objArrayHandle result (THREAD, r);
  1.1090 +  // Fill in result
  1.1091 +  if (klass->oop_is_instance()) {
  1.1092 +    // Regular instance klass, fill in all local interfaces
  1.1093 +    for (int index = 0; index < size; index++) {
  1.1094 +      Klass* k = InstanceKlass::cast(klass())->local_interfaces()->at(index);
  1.1095 +      result->obj_at_put(index, k->java_mirror());
  1.1096 +    }
  1.1097 +  } else {
  1.1098 +    // All arrays implement java.lang.Cloneable and java.io.Serializable
  1.1099 +    result->obj_at_put(0, SystemDictionary::Cloneable_klass()->java_mirror());
  1.1100 +    result->obj_at_put(1, SystemDictionary::Serializable_klass()->java_mirror());
  1.1101 +  }
  1.1102 +  return (jobjectArray) JNIHandles::make_local(env, result());
  1.1103 +JVM_END
  1.1104 +
  1.1105 +
  1.1106 +JVM_ENTRY(jobject, JVM_GetClassLoader(JNIEnv *env, jclass cls))
  1.1107 +  JVMWrapper("JVM_GetClassLoader");
  1.1108 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.1109 +    return NULL;
  1.1110 +  }
  1.1111 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.1112 +  oop loader = k->class_loader();
  1.1113 +  return JNIHandles::make_local(env, loader);
  1.1114 +JVM_END
  1.1115 +
  1.1116 +
  1.1117 +JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
  1.1118 +  JVMWrapper("JVM_IsInterface");
  1.1119 +  oop mirror = JNIHandles::resolve_non_null(cls);
  1.1120 +  if (java_lang_Class::is_primitive(mirror)) {
  1.1121 +    return JNI_FALSE;
  1.1122 +  }
  1.1123 +  Klass* k = java_lang_Class::as_Klass(mirror);
  1.1124 +  jboolean result = k->is_interface();
  1.1125 +  assert(!result || k->oop_is_instance(),
  1.1126 +         "all interfaces are instance types");
  1.1127 +  // The compiler intrinsic for isInterface tests the
  1.1128 +  // Klass::_access_flags bits in the same way.
  1.1129 +  return result;
  1.1130 +JVM_END
  1.1131 +
  1.1132 +
  1.1133 +JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
  1.1134 +  JVMWrapper("JVM_GetClassSigners");
  1.1135 +  JvmtiVMObjectAllocEventCollector oam;
  1.1136 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.1137 +    // There are no signers for primitive types
  1.1138 +    return NULL;
  1.1139 +  }
  1.1140 +
  1.1141 +  objArrayOop signers = java_lang_Class::signers(JNIHandles::resolve_non_null(cls));
  1.1142 +
  1.1143 +  // If there are no signers set in the class, or if the class
  1.1144 +  // is an array, return NULL.
  1.1145 +  if (signers == NULL) return NULL;
  1.1146 +
  1.1147 +  // copy of the signers array
  1.1148 +  Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
  1.1149 +  objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
  1.1150 +  for (int index = 0; index < signers->length(); index++) {
  1.1151 +    signers_copy->obj_at_put(index, signers->obj_at(index));
  1.1152 +  }
  1.1153 +
  1.1154 +  // return the copy
  1.1155 +  return (jobjectArray) JNIHandles::make_local(env, signers_copy);
  1.1156 +JVM_END
  1.1157 +
  1.1158 +
  1.1159 +JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
  1.1160 +  JVMWrapper("JVM_SetClassSigners");
  1.1161 +  if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.1162 +    // This call is ignored for primitive types and arrays.
  1.1163 +    // Signers are only set once, ClassLoader.java, and thus shouldn't
  1.1164 +    // be called with an array.  Only the bootstrap loader creates arrays.
  1.1165 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.1166 +    if (k->oop_is_instance()) {
  1.1167 +      java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers)));
  1.1168 +    }
  1.1169 +  }
  1.1170 +JVM_END
  1.1171 +
  1.1172 +
  1.1173 +JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
  1.1174 +  JVMWrapper("JVM_GetProtectionDomain");
  1.1175 +  if (JNIHandles::resolve(cls) == NULL) {
  1.1176 +    THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
  1.1177 +  }
  1.1178 +
  1.1179 +  if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
  1.1180 +    // Primitive types does not have a protection domain.
  1.1181 +    return NULL;
  1.1182 +  }
  1.1183 +
  1.1184 +  oop pd = java_lang_Class::protection_domain(JNIHandles::resolve(cls));
  1.1185 +  return (jobject) JNIHandles::make_local(env, pd);
  1.1186 +JVM_END
  1.1187 +
  1.1188 +
  1.1189 +static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) {
  1.1190 +  // If there is a security manager and protection domain, check the access
  1.1191 +  // in the protection domain, otherwise it is authorized.
  1.1192 +  if (java_lang_System::has_security_manager()) {
  1.1193 +
  1.1194 +    // For bootstrapping, if pd implies method isn't in the JDK, allow
  1.1195 +    // this context to revert to older behavior.
  1.1196 +    // In this case the isAuthorized field in AccessControlContext is also not
  1.1197 +    // present.
  1.1198 +    if (Universe::protection_domain_implies_method() == NULL) {
  1.1199 +      return true;
  1.1200 +    }
  1.1201 +
  1.1202 +    // Whitelist certain access control contexts
  1.1203 +    if (java_security_AccessControlContext::is_authorized(context)) {
  1.1204 +      return true;
  1.1205 +    }
  1.1206 +
  1.1207 +    oop prot = klass->protection_domain();
  1.1208 +    if (prot != NULL) {
  1.1209 +      // Call pd.implies(new SecurityPermission("createAccessControlContext"))
  1.1210 +      // in the new wrapper.
  1.1211 +      methodHandle m(THREAD, Universe::protection_domain_implies_method());
  1.1212 +      Handle h_prot(THREAD, prot);
  1.1213 +      JavaValue result(T_BOOLEAN);
  1.1214 +      JavaCallArguments args(h_prot);
  1.1215 +      JavaCalls::call(&result, m, &args, CHECK_false);
  1.1216 +      return (result.get_jboolean() != 0);
  1.1217 +    }
  1.1218 +  }
  1.1219 +  return true;
  1.1220 +}
  1.1221 +
  1.1222 +// Create an AccessControlContext with a protection domain with null codesource
  1.1223 +// and null permissions - which gives no permissions.
  1.1224 +oop create_dummy_access_control_context(TRAPS) {
  1.1225 +  InstanceKlass* pd_klass = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass());
  1.1226 +  // new ProtectionDomain(null,null);
  1.1227 +  oop null_protection_domain = pd_klass->allocate_instance(CHECK_NULL);
  1.1228 +  Handle null_pd(THREAD, null_protection_domain);
  1.1229 +
  1.1230 +  // new ProtectionDomain[] {pd};
  1.1231 +  objArrayOop context = oopFactory::new_objArray(pd_klass, 1, CHECK_NULL);
  1.1232 +  context->obj_at_put(0, null_pd());
  1.1233 +
  1.1234 +  // new AccessControlContext(new ProtectionDomain[] {pd})
  1.1235 +  objArrayHandle h_context(THREAD, context);
  1.1236 +  oop result = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL);
  1.1237 +  return result;
  1.1238 +}
  1.1239 +
  1.1240 +JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
  1.1241 +  JVMWrapper("JVM_DoPrivileged");
  1.1242 +
  1.1243 +  if (action == NULL) {
  1.1244 +    THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
  1.1245 +  }
  1.1246 +
  1.1247 +  // Compute the frame initiating the do privileged operation and setup the privileged stack
  1.1248 +  vframeStream vfst(thread);
  1.1249 +  vfst.security_get_caller_frame(1);
  1.1250 +
  1.1251 +  if (vfst.at_end()) {
  1.1252 +    THROW_MSG_0(vmSymbols::java_lang_InternalError(), "no caller?");
  1.1253 +  }
  1.1254 +
  1.1255 +  Method* method        = vfst.method();
  1.1256 +  instanceKlassHandle klass (THREAD, method->method_holder());
  1.1257 +
  1.1258 +  // Check that action object understands "Object run()"
  1.1259 +  Handle h_context;
  1.1260 +  if (context != NULL) {
  1.1261 +    h_context = Handle(THREAD, JNIHandles::resolve(context));
  1.1262 +    bool authorized = is_authorized(h_context, klass, CHECK_NULL);
  1.1263 +    if (!authorized) {
  1.1264 +      // Create an unprivileged access control object and call it's run function
  1.1265 +      // instead.
  1.1266 +      oop noprivs = create_dummy_access_control_context(CHECK_NULL);
  1.1267 +      h_context = Handle(THREAD, noprivs);
  1.1268 +    }
  1.1269 +  }
  1.1270 +
  1.1271 +  // Check that action object understands "Object run()"
  1.1272 +  Handle object (THREAD, JNIHandles::resolve(action));
  1.1273 +
  1.1274 +  // get run() method
  1.1275 +  Method* m_oop = object->klass()->uncached_lookup_method(
  1.1276 +                                           vmSymbols::run_method_name(),
  1.1277 +                                           vmSymbols::void_object_signature(),
  1.1278 +                                           Klass::normal);
  1.1279 +  methodHandle m (THREAD, m_oop);
  1.1280 +  if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) {
  1.1281 +    THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
  1.1282 +  }
  1.1283 +
  1.1284 +  // Stack allocated list of privileged stack elements
  1.1285 +  PrivilegedElement pi;
  1.1286 +  if (!vfst.at_end()) {
  1.1287 +    pi.initialize(&vfst, h_context(), thread->privileged_stack_top(), CHECK_NULL);
  1.1288 +    thread->set_privileged_stack_top(&pi);
  1.1289 +  }
  1.1290 +
  1.1291 +
  1.1292 +  // invoke the Object run() in the action object. We cannot use call_interface here, since the static type
  1.1293 +  // is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
  1.1294 +  Handle pending_exception;
  1.1295 +  JavaValue result(T_OBJECT);
  1.1296 +  JavaCallArguments args(object);
  1.1297 +  JavaCalls::call(&result, m, &args, THREAD);
  1.1298 +
  1.1299 +  // done with action, remove ourselves from the list
  1.1300 +  if (!vfst.at_end()) {
  1.1301 +    assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
  1.1302 +    thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
  1.1303 +  }
  1.1304 +
  1.1305 +  if (HAS_PENDING_EXCEPTION) {
  1.1306 +    pending_exception = Handle(THREAD, PENDING_EXCEPTION);
  1.1307 +    CLEAR_PENDING_EXCEPTION;
  1.1308 +
  1.1309 +    if ( pending_exception->is_a(SystemDictionary::Exception_klass()) &&
  1.1310 +        !pending_exception->is_a(SystemDictionary::RuntimeException_klass())) {
  1.1311 +      // Throw a java.security.PrivilegedActionException(Exception e) exception
  1.1312 +      JavaCallArguments args(pending_exception);
  1.1313 +      THROW_ARG_0(vmSymbols::java_security_PrivilegedActionException(),
  1.1314 +                  vmSymbols::exception_void_signature(),
  1.1315 +                  &args);
  1.1316 +    }
  1.1317 +  }
  1.1318 +
  1.1319 +  if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
  1.1320 +  return JNIHandles::make_local(env, (oop) result.get_jobject());
  1.1321 +JVM_END
  1.1322 +
  1.1323 +
  1.1324 +// Returns the inherited_access_control_context field of the running thread.
  1.1325 +JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls))
  1.1326 +  JVMWrapper("JVM_GetInheritedAccessControlContext");
  1.1327 +  oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj());
  1.1328 +  return JNIHandles::make_local(env, result);
  1.1329 +JVM_END
  1.1330 +
  1.1331 +class RegisterArrayForGC {
  1.1332 + private:
  1.1333 +  JavaThread *_thread;
  1.1334 + public:
  1.1335 +  RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array)  {
  1.1336 +    _thread = thread;
  1.1337 +    _thread->register_array_for_gc(array);
  1.1338 +  }
  1.1339 +
  1.1340 +  ~RegisterArrayForGC() {
  1.1341 +    _thread->register_array_for_gc(NULL);
  1.1342 +  }
  1.1343 +};
  1.1344 +
  1.1345 +
  1.1346 +JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
  1.1347 +  JVMWrapper("JVM_GetStackAccessControlContext");
  1.1348 +  if (!UsePrivilegedStack) return NULL;
  1.1349 +
  1.1350 +  ResourceMark rm(THREAD);
  1.1351 +  GrowableArray<oop>* local_array = new GrowableArray<oop>(12);
  1.1352 +  JvmtiVMObjectAllocEventCollector oam;
  1.1353 +
  1.1354 +  // count the protection domains on the execution stack. We collapse
  1.1355 +  // duplicate consecutive protection domains into a single one, as
  1.1356 +  // well as stopping when we hit a privileged frame.
  1.1357 +
  1.1358 +  // Use vframeStream to iterate through Java frames
  1.1359 +  vframeStream vfst(thread);
  1.1360 +
  1.1361 +  oop previous_protection_domain = NULL;
  1.1362 +  Handle privileged_context(thread, NULL);
  1.1363 +  bool is_privileged = false;
  1.1364 +  oop protection_domain = NULL;
  1.1365 +
  1.1366 +  for(; !vfst.at_end(); vfst.next()) {
  1.1367 +    // get method of frame
  1.1368 +    Method* method = vfst.method();
  1.1369 +    intptr_t* frame_id   = vfst.frame_id();
  1.1370 +
  1.1371 +    // check the privileged frames to see if we have a match
  1.1372 +    if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
  1.1373 +      // this frame is privileged
  1.1374 +      is_privileged = true;
  1.1375 +      privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
  1.1376 +      protection_domain  = thread->privileged_stack_top()->protection_domain();
  1.1377 +    } else {
  1.1378 +      protection_domain = method->method_holder()->protection_domain();
  1.1379 +    }
  1.1380 +
  1.1381 +    if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
  1.1382 +      local_array->push(protection_domain);
  1.1383 +      previous_protection_domain = protection_domain;
  1.1384 +    }
  1.1385 +
  1.1386 +    if (is_privileged) break;
  1.1387 +  }
  1.1388 +
  1.1389 +
  1.1390 +  // either all the domains on the stack were system domains, or
  1.1391 +  // we had a privileged system domain
  1.1392 +  if (local_array->is_empty()) {
  1.1393 +    if (is_privileged && privileged_context.is_null()) return NULL;
  1.1394 +
  1.1395 +    oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
  1.1396 +    return JNIHandles::make_local(env, result);
  1.1397 +  }
  1.1398 +
  1.1399 +  // the resource area must be registered in case of a gc
  1.1400 +  RegisterArrayForGC ragc(thread, local_array);
  1.1401 +  objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(),
  1.1402 +                                                 local_array->length(), CHECK_NULL);
  1.1403 +  objArrayHandle h_context(thread, context);
  1.1404 +  for (int index = 0; index < local_array->length(); index++) {
  1.1405 +    h_context->obj_at_put(index, local_array->at(index));
  1.1406 +  }
  1.1407 +
  1.1408 +  oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
  1.1409 +
  1.1410 +  return JNIHandles::make_local(env, result);
  1.1411 +JVM_END
  1.1412 +
  1.1413 +
  1.1414 +JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
  1.1415 +  JVMWrapper("JVM_IsArrayClass");
  1.1416 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.1417 +  return (k != NULL) && k->oop_is_array() ? true : false;
  1.1418 +JVM_END
  1.1419 +
  1.1420 +
  1.1421 +JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
  1.1422 +  JVMWrapper("JVM_IsPrimitiveClass");
  1.1423 +  oop mirror = JNIHandles::resolve_non_null(cls);
  1.1424 +  return (jboolean) java_lang_Class::is_primitive(mirror);
  1.1425 +JVM_END
  1.1426 +
  1.1427 +
  1.1428 +JVM_ENTRY(jclass, JVM_GetComponentType(JNIEnv *env, jclass cls))
  1.1429 +  JVMWrapper("JVM_GetComponentType");
  1.1430 +  oop mirror = JNIHandles::resolve_non_null(cls);
  1.1431 +  oop result = Reflection::array_component_type(mirror, CHECK_NULL);
  1.1432 +  return (jclass) JNIHandles::make_local(env, result);
  1.1433 +JVM_END
  1.1434 +
  1.1435 +
  1.1436 +JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
  1.1437 +  JVMWrapper("JVM_GetClassModifiers");
  1.1438 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.1439 +    // Primitive type
  1.1440 +    return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
  1.1441 +  }
  1.1442 +
  1.1443 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.1444 +  debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0));
  1.1445 +  assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK");
  1.1446 +  return k->modifier_flags();
  1.1447 +JVM_END
  1.1448 +
  1.1449 +
  1.1450 +// Inner class reflection ///////////////////////////////////////////////////////////////////////////////
  1.1451 +
  1.1452 +JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
  1.1453 +  JvmtiVMObjectAllocEventCollector oam;
  1.1454 +  // ofClass is a reference to a java_lang_Class object. The mirror object
  1.1455 +  // of an InstanceKlass
  1.1456 +
  1.1457 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
  1.1458 +      ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) {
  1.1459 +    oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
  1.1460 +    return (jobjectArray)JNIHandles::make_local(env, result);
  1.1461 +  }
  1.1462 +
  1.1463 +  instanceKlassHandle k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
  1.1464 +  InnerClassesIterator iter(k);
  1.1465 +
  1.1466 +  if (iter.length() == 0) {
  1.1467 +    // Neither an inner nor outer class
  1.1468 +    oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
  1.1469 +    return (jobjectArray)JNIHandles::make_local(env, result);
  1.1470 +  }
  1.1471 +
  1.1472 +  // find inner class info
  1.1473 +  constantPoolHandle cp(thread, k->constants());
  1.1474 +  int length = iter.length();
  1.1475 +
  1.1476 +  // Allocate temp. result array
  1.1477 +  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL);
  1.1478 +  objArrayHandle result (THREAD, r);
  1.1479 +  int members = 0;
  1.1480 +
  1.1481 +  for (; !iter.done(); iter.next()) {
  1.1482 +    int ioff = iter.inner_class_info_index();
  1.1483 +    int ooff = iter.outer_class_info_index();
  1.1484 +
  1.1485 +    if (ioff != 0 && ooff != 0) {
  1.1486 +      // Check to see if the name matches the class we're looking for
  1.1487 +      // before attempting to find the class.
  1.1488 +      if (cp->klass_name_at_matches(k, ooff)) {
  1.1489 +        Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
  1.1490 +        if (outer_klass == k()) {
  1.1491 +           Klass* ik = cp->klass_at(ioff, CHECK_NULL);
  1.1492 +           instanceKlassHandle inner_klass (THREAD, ik);
  1.1493 +
  1.1494 +           // Throws an exception if outer klass has not declared k as
  1.1495 +           // an inner klass
  1.1496 +           Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
  1.1497 +
  1.1498 +           result->obj_at_put(members, inner_klass->java_mirror());
  1.1499 +           members++;
  1.1500 +        }
  1.1501 +      }
  1.1502 +    }
  1.1503 +  }
  1.1504 +
  1.1505 +  if (members != length) {
  1.1506 +    // Return array of right length
  1.1507 +    objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL);
  1.1508 +    for(int i = 0; i < members; i++) {
  1.1509 +      res->obj_at_put(i, result->obj_at(i));
  1.1510 +    }
  1.1511 +    return (jobjectArray)JNIHandles::make_local(env, res);
  1.1512 +  }
  1.1513 +
  1.1514 +  return (jobjectArray)JNIHandles::make_local(env, result());
  1.1515 +JVM_END
  1.1516 +
  1.1517 +
  1.1518 +JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
  1.1519 +{
  1.1520 +  // ofClass is a reference to a java_lang_Class object.
  1.1521 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
  1.1522 +      ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) {
  1.1523 +    return NULL;
  1.1524 +  }
  1.1525 +
  1.1526 +  bool inner_is_member = false;
  1.1527 +  Klass* outer_klass
  1.1528 +    = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))
  1.1529 +                          )->compute_enclosing_class(&inner_is_member, CHECK_NULL);
  1.1530 +  if (outer_klass == NULL)  return NULL;  // already a top-level class
  1.1531 +  if (!inner_is_member)  return NULL;     // an anonymous class (inside a method)
  1.1532 +  return (jclass) JNIHandles::make_local(env, outer_klass->java_mirror());
  1.1533 +}
  1.1534 +JVM_END
  1.1535 +
  1.1536 +// should be in InstanceKlass.cpp, but is here for historical reasons
  1.1537 +Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k,
  1.1538 +                                                     bool* inner_is_member,
  1.1539 +                                                     TRAPS) {
  1.1540 +  Thread* thread = THREAD;
  1.1541 +  InnerClassesIterator iter(k);
  1.1542 +  if (iter.length() == 0) {
  1.1543 +    // No inner class info => no declaring class
  1.1544 +    return NULL;
  1.1545 +  }
  1.1546 +
  1.1547 +  constantPoolHandle i_cp(thread, k->constants());
  1.1548 +
  1.1549 +  bool found = false;
  1.1550 +  Klass* ok;
  1.1551 +  instanceKlassHandle outer_klass;
  1.1552 +  *inner_is_member = false;
  1.1553 +
  1.1554 +  // Find inner_klass attribute
  1.1555 +  for (; !iter.done() && !found; iter.next()) {
  1.1556 +    int ioff = iter.inner_class_info_index();
  1.1557 +    int ooff = iter.outer_class_info_index();
  1.1558 +    int noff = iter.inner_name_index();
  1.1559 +    if (ioff != 0) {
  1.1560 +      // Check to see if the name matches the class we're looking for
  1.1561 +      // before attempting to find the class.
  1.1562 +      if (i_cp->klass_name_at_matches(k, ioff)) {
  1.1563 +        Klass* inner_klass = i_cp->klass_at(ioff, CHECK_NULL);
  1.1564 +        found = (k() == inner_klass);
  1.1565 +        if (found && ooff != 0) {
  1.1566 +          ok = i_cp->klass_at(ooff, CHECK_NULL);
  1.1567 +          outer_klass = instanceKlassHandle(thread, ok);
  1.1568 +          *inner_is_member = true;
  1.1569 +        }
  1.1570 +      }
  1.1571 +    }
  1.1572 +  }
  1.1573 +
  1.1574 +  if (found && outer_klass.is_null()) {
  1.1575 +    // It may be anonymous; try for that.
  1.1576 +    int encl_method_class_idx = k->enclosing_method_class_index();
  1.1577 +    if (encl_method_class_idx != 0) {
  1.1578 +      ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
  1.1579 +      outer_klass = instanceKlassHandle(thread, ok);
  1.1580 +      *inner_is_member = false;
  1.1581 +    }
  1.1582 +  }
  1.1583 +
  1.1584 +  // If no inner class attribute found for this class.
  1.1585 +  if (outer_klass.is_null())  return NULL;
  1.1586 +
  1.1587 +  // Throws an exception if outer klass has not declared k as an inner klass
  1.1588 +  // We need evidence that each klass knows about the other, or else
  1.1589 +  // the system could allow a spoof of an inner class to gain access rights.
  1.1590 +  Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL);
  1.1591 +  return outer_klass();
  1.1592 +}
  1.1593 +
  1.1594 +JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
  1.1595 +  assert (cls != NULL, "illegal class");
  1.1596 +  JVMWrapper("JVM_GetClassSignature");
  1.1597 +  JvmtiVMObjectAllocEventCollector oam;
  1.1598 +  ResourceMark rm(THREAD);
  1.1599 +  // Return null for arrays and primatives
  1.1600 +  if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
  1.1601 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
  1.1602 +    if (k->oop_is_instance()) {
  1.1603 +      Symbol* sym = InstanceKlass::cast(k)->generic_signature();
  1.1604 +      if (sym == NULL) return NULL;
  1.1605 +      Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
  1.1606 +      return (jstring) JNIHandles::make_local(env, str());
  1.1607 +    }
  1.1608 +  }
  1.1609 +  return NULL;
  1.1610 +JVM_END
  1.1611 +
  1.1612 +
  1.1613 +JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
  1.1614 +  assert (cls != NULL, "illegal class");
  1.1615 +  JVMWrapper("JVM_GetClassAnnotations");
  1.1616 +
  1.1617 +  // Return null for arrays and primitives
  1.1618 +  if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
  1.1619 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
  1.1620 +    if (k->oop_is_instance()) {
  1.1621 +      typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL);
  1.1622 +      return (jbyteArray) JNIHandles::make_local(env, a);
  1.1623 +    }
  1.1624 +  }
  1.1625 +  return NULL;
  1.1626 +JVM_END
  1.1627 +
  1.1628 +
  1.1629 +static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) {
  1.1630 +  // some of this code was adapted from from jni_FromReflectedField
  1.1631 +
  1.1632 +  oop reflected = JNIHandles::resolve_non_null(field);
  1.1633 +  oop mirror    = java_lang_reflect_Field::clazz(reflected);
  1.1634 +  Klass* k    = java_lang_Class::as_Klass(mirror);
  1.1635 +  int slot      = java_lang_reflect_Field::slot(reflected);
  1.1636 +  int modifiers = java_lang_reflect_Field::modifiers(reflected);
  1.1637 +
  1.1638 +  KlassHandle kh(THREAD, k);
  1.1639 +  intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot);
  1.1640 +
  1.1641 +  if (modifiers & JVM_ACC_STATIC) {
  1.1642 +    // for static fields we only look in the current class
  1.1643 +    if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) {
  1.1644 +      assert(false, "cannot find static field");
  1.1645 +      return false;
  1.1646 +    }
  1.1647 +  } else {
  1.1648 +    // for instance fields we start with the current class and work
  1.1649 +    // our way up through the superclass chain
  1.1650 +    if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) {
  1.1651 +      assert(false, "cannot find instance field");
  1.1652 +      return false;
  1.1653 +    }
  1.1654 +  }
  1.1655 +  return true;
  1.1656 +}
  1.1657 +
  1.1658 +JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
  1.1659 +  // field is a handle to a java.lang.reflect.Field object
  1.1660 +  assert(field != NULL, "illegal field");
  1.1661 +  JVMWrapper("JVM_GetFieldAnnotations");
  1.1662 +
  1.1663 +  fieldDescriptor fd;
  1.1664 +  bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
  1.1665 +  if (!gotFd) {
  1.1666 +    return NULL;
  1.1667 +  }
  1.1668 +
  1.1669 +  return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD));
  1.1670 +JVM_END
  1.1671 +
  1.1672 +
  1.1673 +static Method* jvm_get_method_common(jobject method) {
  1.1674 +  // some of this code was adapted from from jni_FromReflectedMethod
  1.1675 +
  1.1676 +  oop reflected = JNIHandles::resolve_non_null(method);
  1.1677 +  oop mirror    = NULL;
  1.1678 +  int slot      = 0;
  1.1679 +
  1.1680 +  if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
  1.1681 +    mirror = java_lang_reflect_Constructor::clazz(reflected);
  1.1682 +    slot   = java_lang_reflect_Constructor::slot(reflected);
  1.1683 +  } else {
  1.1684 +    assert(reflected->klass() == SystemDictionary::reflect_Method_klass(),
  1.1685 +           "wrong type");
  1.1686 +    mirror = java_lang_reflect_Method::clazz(reflected);
  1.1687 +    slot   = java_lang_reflect_Method::slot(reflected);
  1.1688 +  }
  1.1689 +  Klass* k = java_lang_Class::as_Klass(mirror);
  1.1690 +
  1.1691 +  Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
  1.1692 +  assert(m != NULL, "cannot find method");
  1.1693 +  return m;  // caller has to deal with NULL in product mode
  1.1694 +}
  1.1695 +
  1.1696 +
  1.1697 +JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
  1.1698 +  JVMWrapper("JVM_GetMethodAnnotations");
  1.1699 +
  1.1700 +  // method is a handle to a java.lang.reflect.Method object
  1.1701 +  Method* m = jvm_get_method_common(method);
  1.1702 +  if (m == NULL) {
  1.1703 +    return NULL;
  1.1704 +  }
  1.1705 +
  1.1706 +  return (jbyteArray) JNIHandles::make_local(env,
  1.1707 +    Annotations::make_java_array(m->annotations(), THREAD));
  1.1708 +JVM_END
  1.1709 +
  1.1710 +
  1.1711 +JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
  1.1712 +  JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
  1.1713 +
  1.1714 +  // method is a handle to a java.lang.reflect.Method object
  1.1715 +  Method* m = jvm_get_method_common(method);
  1.1716 +  if (m == NULL) {
  1.1717 +    return NULL;
  1.1718 +  }
  1.1719 +
  1.1720 +  return (jbyteArray) JNIHandles::make_local(env,
  1.1721 +    Annotations::make_java_array(m->annotation_default(), THREAD));
  1.1722 +JVM_END
  1.1723 +
  1.1724 +
  1.1725 +JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
  1.1726 +  JVMWrapper("JVM_GetMethodParameterAnnotations");
  1.1727 +
  1.1728 +  // method is a handle to a java.lang.reflect.Method object
  1.1729 +  Method* m = jvm_get_method_common(method);
  1.1730 +  if (m == NULL) {
  1.1731 +    return NULL;
  1.1732 +  }
  1.1733 +
  1.1734 +  return (jbyteArray) JNIHandles::make_local(env,
  1.1735 +    Annotations::make_java_array(m->parameter_annotations(), THREAD));
  1.1736 +JVM_END
  1.1737 +
  1.1738 +/* Type use annotations support (JDK 1.8) */
  1.1739 +
  1.1740 +JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls))
  1.1741 +  assert (cls != NULL, "illegal class");
  1.1742 +  JVMWrapper("JVM_GetClassTypeAnnotations");
  1.1743 +  ResourceMark rm(THREAD);
  1.1744 +  // Return null for arrays and primitives
  1.1745 +  if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
  1.1746 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
  1.1747 +    if (k->oop_is_instance()) {
  1.1748 +      AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations();
  1.1749 +      if (type_annotations != NULL) {
  1.1750 +        typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
  1.1751 +        return (jbyteArray) JNIHandles::make_local(env, a);
  1.1752 +      }
  1.1753 +    }
  1.1754 +  }
  1.1755 +  return NULL;
  1.1756 +JVM_END
  1.1757 +
  1.1758 +JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method))
  1.1759 +  assert (method != NULL, "illegal method");
  1.1760 +  JVMWrapper("JVM_GetMethodTypeAnnotations");
  1.1761 +
  1.1762 +  // method is a handle to a java.lang.reflect.Method object
  1.1763 +  Method* m = jvm_get_method_common(method);
  1.1764 +  if (m == NULL) {
  1.1765 +    return NULL;
  1.1766 +  }
  1.1767 +
  1.1768 +  AnnotationArray* type_annotations = m->type_annotations();
  1.1769 +  if (type_annotations != NULL) {
  1.1770 +    typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
  1.1771 +    return (jbyteArray) JNIHandles::make_local(env, a);
  1.1772 +  }
  1.1773 +
  1.1774 +  return NULL;
  1.1775 +JVM_END
  1.1776 +
  1.1777 +JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
  1.1778 +  assert (field != NULL, "illegal field");
  1.1779 +  JVMWrapper("JVM_GetFieldTypeAnnotations");
  1.1780 +
  1.1781 +  fieldDescriptor fd;
  1.1782 +  bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
  1.1783 +  if (!gotFd) {
  1.1784 +    return NULL;
  1.1785 +  }
  1.1786 +
  1.1787 +  return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
  1.1788 +JVM_END
  1.1789 +
  1.1790 +static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
  1.1791 +  if (!cp->is_within_bounds(index)) {
  1.1792 +    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
  1.1793 +  }
  1.1794 +}
  1.1795 +
  1.1796 +JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
  1.1797 +{
  1.1798 +  JVMWrapper("JVM_GetMethodParameters");
  1.1799 +  // method is a handle to a java.lang.reflect.Method object
  1.1800 +  Method* method_ptr = jvm_get_method_common(method);
  1.1801 +  methodHandle mh (THREAD, method_ptr);
  1.1802 +  Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
  1.1803 +  const int num_params = mh->method_parameters_length();
  1.1804 +
  1.1805 +  if (0 != num_params) {
  1.1806 +    // make sure all the symbols are properly formatted
  1.1807 +    for (int i = 0; i < num_params; i++) {
  1.1808 +      MethodParametersElement* params = mh->method_parameters_start();
  1.1809 +      int index = params[i].name_cp_index;
  1.1810 +      bounds_check(mh->constants(), index, CHECK_NULL);
  1.1811 +
  1.1812 +      if (0 != index && !mh->constants()->tag_at(index).is_utf8()) {
  1.1813 +        THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
  1.1814 +                    "Wrong type at constant pool index");
  1.1815 +      }
  1.1816 +
  1.1817 +    }
  1.1818 +
  1.1819 +    objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL);
  1.1820 +    objArrayHandle result (THREAD, result_oop);
  1.1821 +
  1.1822 +    for (int i = 0; i < num_params; i++) {
  1.1823 +      MethodParametersElement* params = mh->method_parameters_start();
  1.1824 +      // For a 0 index, give a NULL symbol
  1.1825 +      Symbol* sym = 0 != params[i].name_cp_index ?
  1.1826 +        mh->constants()->symbol_at(params[i].name_cp_index) : NULL;
  1.1827 +      int flags = params[i].flags;
  1.1828 +      oop param = Reflection::new_parameter(reflected_method, i, sym,
  1.1829 +                                            flags, CHECK_NULL);
  1.1830 +      result->obj_at_put(i, param);
  1.1831 +    }
  1.1832 +    return (jobjectArray)JNIHandles::make_local(env, result());
  1.1833 +  } else {
  1.1834 +    return (jobjectArray)NULL;
  1.1835 +  }
  1.1836 +}
  1.1837 +JVM_END
  1.1838 +
  1.1839 +// New (JDK 1.4) reflection implementation /////////////////////////////////////
  1.1840 +
  1.1841 +JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
  1.1842 +{
  1.1843 +  JVMWrapper("JVM_GetClassDeclaredFields");
  1.1844 +  JvmtiVMObjectAllocEventCollector oam;
  1.1845 +
  1.1846 +  // Exclude primitive types and array types
  1.1847 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
  1.1848 +      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
  1.1849 +    // Return empty array
  1.1850 +    oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
  1.1851 +    return (jobjectArray) JNIHandles::make_local(env, res);
  1.1852 +  }
  1.1853 +
  1.1854 +  instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
  1.1855 +  constantPoolHandle cp(THREAD, k->constants());
  1.1856 +
  1.1857 +  // Ensure class is linked
  1.1858 +  k->link_class(CHECK_NULL);
  1.1859 +
  1.1860 +  // 4496456 We need to filter out java.lang.Throwable.backtrace
  1.1861 +  bool skip_backtrace = false;
  1.1862 +
  1.1863 +  // Allocate result
  1.1864 +  int num_fields;
  1.1865 +
  1.1866 +  if (publicOnly) {
  1.1867 +    num_fields = 0;
  1.1868 +    for (JavaFieldStream fs(k()); !fs.done(); fs.next()) {
  1.1869 +      if (fs.access_flags().is_public()) ++num_fields;
  1.1870 +    }
  1.1871 +  } else {
  1.1872 +    num_fields = k->java_fields_count();
  1.1873 +
  1.1874 +    if (k() == SystemDictionary::Throwable_klass()) {
  1.1875 +      num_fields--;
  1.1876 +      skip_backtrace = true;
  1.1877 +    }
  1.1878 +  }
  1.1879 +
  1.1880 +  objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
  1.1881 +  objArrayHandle result (THREAD, r);
  1.1882 +
  1.1883 +  int out_idx = 0;
  1.1884 +  fieldDescriptor fd;
  1.1885 +  for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
  1.1886 +    if (skip_backtrace) {
  1.1887 +      // 4496456 skip java.lang.Throwable.backtrace
  1.1888 +      int offset = fs.offset();
  1.1889 +      if (offset == java_lang_Throwable::get_backtrace_offset()) continue;
  1.1890 +    }
  1.1891 +
  1.1892 +    if (!publicOnly || fs.access_flags().is_public()) {
  1.1893 +      fd.reinitialize(k(), fs.index());
  1.1894 +      oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
  1.1895 +      result->obj_at_put(out_idx, field);
  1.1896 +      ++out_idx;
  1.1897 +    }
  1.1898 +  }
  1.1899 +  assert(out_idx == num_fields, "just checking");
  1.1900 +  return (jobjectArray) JNIHandles::make_local(env, result());
  1.1901 +}
  1.1902 +JVM_END
  1.1903 +
  1.1904 +static bool select_method(methodHandle method, bool want_constructor) {
  1.1905 +  if (want_constructor) {
  1.1906 +    return (method->is_initializer() && !method->is_static());
  1.1907 +  } else {
  1.1908 +    return  (!method->is_initializer() && !method->is_overpass());
  1.1909 +  }
  1.1910 +}
  1.1911 +
  1.1912 +static jobjectArray get_class_declared_methods_helper(
  1.1913 +                                  JNIEnv *env,
  1.1914 +                                  jclass ofClass, jboolean publicOnly,
  1.1915 +                                  bool want_constructor,
  1.1916 +                                  Klass* klass, TRAPS) {
  1.1917 +
  1.1918 +  JvmtiVMObjectAllocEventCollector oam;
  1.1919 +
  1.1920 +  // Exclude primitive types and array types
  1.1921 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
  1.1922 +      || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
  1.1923 +    // Return empty array
  1.1924 +    oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
  1.1925 +    return (jobjectArray) JNIHandles::make_local(env, res);
  1.1926 +  }
  1.1927 +
  1.1928 +  instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
  1.1929 +
  1.1930 +  // Ensure class is linked
  1.1931 +  k->link_class(CHECK_NULL);
  1.1932 +
  1.1933 +  Array<Method*>* methods = k->methods();
  1.1934 +  int methods_length = methods->length();
  1.1935 +
  1.1936 +  // Save original method_idnum in case of redefinition, which can change
  1.1937 +  // the idnum of obsolete methods.  The new method will have the same idnum
  1.1938 +  // but if we refresh the methods array, the counts will be wrong.
  1.1939 +  ResourceMark rm(THREAD);
  1.1940 +  GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
  1.1941 +  int num_methods = 0;
  1.1942 +
  1.1943 +  for (int i = 0; i < methods_length; i++) {
  1.1944 +    methodHandle method(THREAD, methods->at(i));
  1.1945 +    if (select_method(method, want_constructor)) {
  1.1946 +      if (!publicOnly || method->is_public()) {
  1.1947 +        idnums->push(method->method_idnum());
  1.1948 +        ++num_methods;
  1.1949 +      }
  1.1950 +    }
  1.1951 +  }
  1.1952 +
  1.1953 +  // Allocate result
  1.1954 +  objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
  1.1955 +  objArrayHandle result (THREAD, r);
  1.1956 +
  1.1957 +  // Now just put the methods that we selected above, but go by their idnum
  1.1958 +  // in case of redefinition.  The methods can be redefined at any safepoint,
  1.1959 +  // so above when allocating the oop array and below when creating reflect
  1.1960 +  // objects.
  1.1961 +  for (int i = 0; i < num_methods; i++) {
  1.1962 +    methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
  1.1963 +    if (method.is_null()) {
  1.1964 +      // Method may have been deleted and seems this API can handle null
  1.1965 +      // Otherwise should probably put a method that throws NSME
  1.1966 +      result->obj_at_put(i, NULL);
  1.1967 +    } else {
  1.1968 +      oop m;
  1.1969 +      if (want_constructor) {
  1.1970 +        m = Reflection::new_constructor(method, CHECK_NULL);
  1.1971 +      } else {
  1.1972 +        m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
  1.1973 +      }
  1.1974 +      result->obj_at_put(i, m);
  1.1975 +    }
  1.1976 +  }
  1.1977 +
  1.1978 +  return (jobjectArray) JNIHandles::make_local(env, result());
  1.1979 +}
  1.1980 +
  1.1981 +JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
  1.1982 +{
  1.1983 +  JVMWrapper("JVM_GetClassDeclaredMethods");
  1.1984 +  return get_class_declared_methods_helper(env, ofClass, publicOnly,
  1.1985 +                                           /*want_constructor*/ false,
  1.1986 +                                           SystemDictionary::reflect_Method_klass(), THREAD);
  1.1987 +}
  1.1988 +JVM_END
  1.1989 +
  1.1990 +JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
  1.1991 +{
  1.1992 +  JVMWrapper("JVM_GetClassDeclaredConstructors");
  1.1993 +  return get_class_declared_methods_helper(env, ofClass, publicOnly,
  1.1994 +                                           /*want_constructor*/ true,
  1.1995 +                                           SystemDictionary::reflect_Constructor_klass(), THREAD);
  1.1996 +}
  1.1997 +JVM_END
  1.1998 +
  1.1999 +JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
  1.2000 +{
  1.2001 +  JVMWrapper("JVM_GetClassAccessFlags");
  1.2002 +  if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.2003 +    // Primitive type
  1.2004 +    return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
  1.2005 +  }
  1.2006 +
  1.2007 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2008 +  return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS;
  1.2009 +}
  1.2010 +JVM_END
  1.2011 +
  1.2012 +
  1.2013 +// Constant pool access //////////////////////////////////////////////////////////
  1.2014 +
  1.2015 +JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
  1.2016 +{
  1.2017 +  JVMWrapper("JVM_GetClassConstantPool");
  1.2018 +  JvmtiVMObjectAllocEventCollector oam;
  1.2019 +
  1.2020 +  // Return null for primitives and arrays
  1.2021 +  if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
  1.2022 +    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2023 +    if (k->oop_is_instance()) {
  1.2024 +      instanceKlassHandle k_h(THREAD, k);
  1.2025 +      Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL);
  1.2026 +      sun_reflect_ConstantPool::set_cp(jcp(), k_h->constants());
  1.2027 +      return JNIHandles::make_local(jcp());
  1.2028 +    }
  1.2029 +  }
  1.2030 +  return NULL;
  1.2031 +}
  1.2032 +JVM_END
  1.2033 +
  1.2034 +
  1.2035 +JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused))
  1.2036 +{
  1.2037 +  JVMWrapper("JVM_ConstantPoolGetSize");
  1.2038 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2039 +  return cp->length();
  1.2040 +}
  1.2041 +JVM_END
  1.2042 +
  1.2043 +
  1.2044 +JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2045 +{
  1.2046 +  JVMWrapper("JVM_ConstantPoolGetClassAt");
  1.2047 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2048 +  bounds_check(cp, index, CHECK_NULL);
  1.2049 +  constantTag tag = cp->tag_at(index);
  1.2050 +  if (!tag.is_klass() && !tag.is_unresolved_klass()) {
  1.2051 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2052 +  }
  1.2053 +  Klass* k = cp->klass_at(index, CHECK_NULL);
  1.2054 +  return (jclass) JNIHandles::make_local(k->java_mirror());
  1.2055 +}
  1.2056 +JVM_END
  1.2057 +
  1.2058 +JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2059 +{
  1.2060 +  JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
  1.2061 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2062 +  bounds_check(cp, index, CHECK_NULL);
  1.2063 +  constantTag tag = cp->tag_at(index);
  1.2064 +  if (!tag.is_klass() && !tag.is_unresolved_klass()) {
  1.2065 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2066 +  }
  1.2067 +  Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
  1.2068 +  if (k == NULL) return NULL;
  1.2069 +  return (jclass) JNIHandles::make_local(k->java_mirror());
  1.2070 +}
  1.2071 +JVM_END
  1.2072 +
  1.2073 +static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
  1.2074 +  constantTag tag = cp->tag_at(index);
  1.2075 +  if (!tag.is_method() && !tag.is_interface_method()) {
  1.2076 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2077 +  }
  1.2078 +  int klass_ref  = cp->uncached_klass_ref_index_at(index);
  1.2079 +  Klass* k_o;
  1.2080 +  if (force_resolution) {
  1.2081 +    k_o = cp->klass_at(klass_ref, CHECK_NULL);
  1.2082 +  } else {
  1.2083 +    k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
  1.2084 +    if (k_o == NULL) return NULL;
  1.2085 +  }
  1.2086 +  instanceKlassHandle k(THREAD, k_o);
  1.2087 +  Symbol* name = cp->uncached_name_ref_at(index);
  1.2088 +  Symbol* sig  = cp->uncached_signature_ref_at(index);
  1.2089 +  methodHandle m (THREAD, k->find_method(name, sig));
  1.2090 +  if (m.is_null()) {
  1.2091 +    THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
  1.2092 +  }
  1.2093 +  oop method;
  1.2094 +  if (!m->is_initializer() || m->is_static()) {
  1.2095 +    method = Reflection::new_method(m, true, true, CHECK_NULL);
  1.2096 +  } else {
  1.2097 +    method = Reflection::new_constructor(m, CHECK_NULL);
  1.2098 +  }
  1.2099 +  return JNIHandles::make_local(method);
  1.2100 +}
  1.2101 +
  1.2102 +JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2103 +{
  1.2104 +  JVMWrapper("JVM_ConstantPoolGetMethodAt");
  1.2105 +  JvmtiVMObjectAllocEventCollector oam;
  1.2106 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2107 +  bounds_check(cp, index, CHECK_NULL);
  1.2108 +  jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
  1.2109 +  return res;
  1.2110 +}
  1.2111 +JVM_END
  1.2112 +
  1.2113 +JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2114 +{
  1.2115 +  JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
  1.2116 +  JvmtiVMObjectAllocEventCollector oam;
  1.2117 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2118 +  bounds_check(cp, index, CHECK_NULL);
  1.2119 +  jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);
  1.2120 +  return res;
  1.2121 +}
  1.2122 +JVM_END
  1.2123 +
  1.2124 +static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
  1.2125 +  constantTag tag = cp->tag_at(index);
  1.2126 +  if (!tag.is_field()) {
  1.2127 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2128 +  }
  1.2129 +  int klass_ref  = cp->uncached_klass_ref_index_at(index);
  1.2130 +  Klass* k_o;
  1.2131 +  if (force_resolution) {
  1.2132 +    k_o = cp->klass_at(klass_ref, CHECK_NULL);
  1.2133 +  } else {
  1.2134 +    k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
  1.2135 +    if (k_o == NULL) return NULL;
  1.2136 +  }
  1.2137 +  instanceKlassHandle k(THREAD, k_o);
  1.2138 +  Symbol* name = cp->uncached_name_ref_at(index);
  1.2139 +  Symbol* sig  = cp->uncached_signature_ref_at(index);
  1.2140 +  fieldDescriptor fd;
  1.2141 +  Klass* target_klass = k->find_field(name, sig, &fd);
  1.2142 +  if (target_klass == NULL) {
  1.2143 +    THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class");
  1.2144 +  }
  1.2145 +  oop field = Reflection::new_field(&fd, true, CHECK_NULL);
  1.2146 +  return JNIHandles::make_local(field);
  1.2147 +}
  1.2148 +
  1.2149 +JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index))
  1.2150 +{
  1.2151 +  JVMWrapper("JVM_ConstantPoolGetFieldAt");
  1.2152 +  JvmtiVMObjectAllocEventCollector oam;
  1.2153 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2154 +  bounds_check(cp, index, CHECK_NULL);
  1.2155 +  jobject res = get_field_at_helper(cp, index, true, CHECK_NULL);
  1.2156 +  return res;
  1.2157 +}
  1.2158 +JVM_END
  1.2159 +
  1.2160 +JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2161 +{
  1.2162 +  JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded");
  1.2163 +  JvmtiVMObjectAllocEventCollector oam;
  1.2164 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2165 +  bounds_check(cp, index, CHECK_NULL);
  1.2166 +  jobject res = get_field_at_helper(cp, index, false, CHECK_NULL);
  1.2167 +  return res;
  1.2168 +}
  1.2169 +JVM_END
  1.2170 +
  1.2171 +JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2172 +{
  1.2173 +  JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt");
  1.2174 +  JvmtiVMObjectAllocEventCollector oam;
  1.2175 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2176 +  bounds_check(cp, index, CHECK_NULL);
  1.2177 +  constantTag tag = cp->tag_at(index);
  1.2178 +  if (!tag.is_field_or_method()) {
  1.2179 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2180 +  }
  1.2181 +  int klass_ref = cp->uncached_klass_ref_index_at(index);
  1.2182 +  Symbol*  klass_name  = cp->klass_name_at(klass_ref);
  1.2183 +  Symbol*  member_name = cp->uncached_name_ref_at(index);
  1.2184 +  Symbol*  member_sig  = cp->uncached_signature_ref_at(index);
  1.2185 +  objArrayOop  dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL);
  1.2186 +  objArrayHandle dest(THREAD, dest_o);
  1.2187 +  Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL);
  1.2188 +  dest->obj_at_put(0, str());
  1.2189 +  str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
  1.2190 +  dest->obj_at_put(1, str());
  1.2191 +  str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
  1.2192 +  dest->obj_at_put(2, str());
  1.2193 +  return (jobjectArray) JNIHandles::make_local(dest());
  1.2194 +}
  1.2195 +JVM_END
  1.2196 +
  1.2197 +JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2198 +{
  1.2199 +  JVMWrapper("JVM_ConstantPoolGetIntAt");
  1.2200 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2201 +  bounds_check(cp, index, CHECK_0);
  1.2202 +  constantTag tag = cp->tag_at(index);
  1.2203 +  if (!tag.is_int()) {
  1.2204 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2205 +  }
  1.2206 +  return cp->int_at(index);
  1.2207 +}
  1.2208 +JVM_END
  1.2209 +
  1.2210 +JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2211 +{
  1.2212 +  JVMWrapper("JVM_ConstantPoolGetLongAt");
  1.2213 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2214 +  bounds_check(cp, index, CHECK_(0L));
  1.2215 +  constantTag tag = cp->tag_at(index);
  1.2216 +  if (!tag.is_long()) {
  1.2217 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2218 +  }
  1.2219 +  return cp->long_at(index);
  1.2220 +}
  1.2221 +JVM_END
  1.2222 +
  1.2223 +JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2224 +{
  1.2225 +  JVMWrapper("JVM_ConstantPoolGetFloatAt");
  1.2226 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2227 +  bounds_check(cp, index, CHECK_(0.0f));
  1.2228 +  constantTag tag = cp->tag_at(index);
  1.2229 +  if (!tag.is_float()) {
  1.2230 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2231 +  }
  1.2232 +  return cp->float_at(index);
  1.2233 +}
  1.2234 +JVM_END
  1.2235 +
  1.2236 +JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2237 +{
  1.2238 +  JVMWrapper("JVM_ConstantPoolGetDoubleAt");
  1.2239 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2240 +  bounds_check(cp, index, CHECK_(0.0));
  1.2241 +  constantTag tag = cp->tag_at(index);
  1.2242 +  if (!tag.is_double()) {
  1.2243 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2244 +  }
  1.2245 +  return cp->double_at(index);
  1.2246 +}
  1.2247 +JVM_END
  1.2248 +
  1.2249 +JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2250 +{
  1.2251 +  JVMWrapper("JVM_ConstantPoolGetStringAt");
  1.2252 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2253 +  bounds_check(cp, index, CHECK_NULL);
  1.2254 +  constantTag tag = cp->tag_at(index);
  1.2255 +  if (!tag.is_string()) {
  1.2256 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2257 +  }
  1.2258 +  oop str = cp->string_at(index, CHECK_NULL);
  1.2259 +  return (jstring) JNIHandles::make_local(str);
  1.2260 +}
  1.2261 +JVM_END
  1.2262 +
  1.2263 +JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index))
  1.2264 +{
  1.2265 +  JVMWrapper("JVM_ConstantPoolGetUTF8At");
  1.2266 +  JvmtiVMObjectAllocEventCollector oam;
  1.2267 +  constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
  1.2268 +  bounds_check(cp, index, CHECK_NULL);
  1.2269 +  constantTag tag = cp->tag_at(index);
  1.2270 +  if (!tag.is_symbol()) {
  1.2271 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
  1.2272 +  }
  1.2273 +  Symbol* sym = cp->symbol_at(index);
  1.2274 +  Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
  1.2275 +  return (jstring) JNIHandles::make_local(str());
  1.2276 +}
  1.2277 +JVM_END
  1.2278 +
  1.2279 +
  1.2280 +// Assertion support. //////////////////////////////////////////////////////////
  1.2281 +
  1.2282 +JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
  1.2283 +  JVMWrapper("JVM_DesiredAssertionStatus");
  1.2284 +  assert(cls != NULL, "bad class");
  1.2285 +
  1.2286 +  oop r = JNIHandles::resolve(cls);
  1.2287 +  assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed");
  1.2288 +  if (java_lang_Class::is_primitive(r)) return false;
  1.2289 +
  1.2290 +  Klass* k = java_lang_Class::as_Klass(r);
  1.2291 +  assert(k->oop_is_instance(), "must be an instance klass");
  1.2292 +  if (! k->oop_is_instance()) return false;
  1.2293 +
  1.2294 +  ResourceMark rm(THREAD);
  1.2295 +  const char* name = k->name()->as_C_string();
  1.2296 +  bool system_class = k->class_loader() == NULL;
  1.2297 +  return JavaAssertions::enabled(name, system_class);
  1.2298 +
  1.2299 +JVM_END
  1.2300 +
  1.2301 +
  1.2302 +// Return a new AssertionStatusDirectives object with the fields filled in with
  1.2303 +// command-line assertion arguments (i.e., -ea, -da).
  1.2304 +JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
  1.2305 +  JVMWrapper("JVM_AssertionStatusDirectives");
  1.2306 +  JvmtiVMObjectAllocEventCollector oam;
  1.2307 +  oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
  1.2308 +  return JNIHandles::make_local(env, asd);
  1.2309 +JVM_END
  1.2310 +
  1.2311 +// Verification ////////////////////////////////////////////////////////////////////////////////
  1.2312 +
  1.2313 +// Reflection for the verifier /////////////////////////////////////////////////////////////////
  1.2314 +
  1.2315 +// RedefineClasses support: bug 6214132 caused verification to fail.
  1.2316 +// All functions from this section should call the jvmtiThreadSate function:
  1.2317 +//   Klass* class_to_verify_considering_redefinition(Klass* klass).
  1.2318 +// The function returns a Klass* of the _scratch_class if the verifier
  1.2319 +// was invoked in the middle of the class redefinition.
  1.2320 +// Otherwise it returns its argument value which is the _the_class Klass*.
  1.2321 +// Please, refer to the description in the jvmtiThreadSate.hpp.
  1.2322 +
  1.2323 +JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
  1.2324 +  JVMWrapper("JVM_GetClassNameUTF");
  1.2325 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2326 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2327 +  return k->name()->as_utf8();
  1.2328 +JVM_END
  1.2329 +
  1.2330 +
  1.2331 +JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
  1.2332 +  JVMWrapper("JVM_GetClassCPTypes");
  1.2333 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2334 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2335 +  // types will have length zero if this is not an InstanceKlass
  1.2336 +  // (length is determined by call to JVM_GetClassCPEntriesCount)
  1.2337 +  if (k->oop_is_instance()) {
  1.2338 +    ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2339 +    for (int index = cp->length() - 1; index >= 0; index--) {
  1.2340 +      constantTag tag = cp->tag_at(index);
  1.2341 +      types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value();
  1.2342 +  }
  1.2343 +  }
  1.2344 +JVM_END
  1.2345 +
  1.2346 +
  1.2347 +JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
  1.2348 +  JVMWrapper("JVM_GetClassCPEntriesCount");
  1.2349 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2350 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2351 +  if (!k->oop_is_instance())
  1.2352 +    return 0;
  1.2353 +  return InstanceKlass::cast(k)->constants()->length();
  1.2354 +JVM_END
  1.2355 +
  1.2356 +
  1.2357 +JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
  1.2358 +  JVMWrapper("JVM_GetClassFieldsCount");
  1.2359 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2360 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2361 +  if (!k->oop_is_instance())
  1.2362 +    return 0;
  1.2363 +  return InstanceKlass::cast(k)->java_fields_count();
  1.2364 +JVM_END
  1.2365 +
  1.2366 +
  1.2367 +JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
  1.2368 +  JVMWrapper("JVM_GetClassMethodsCount");
  1.2369 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2370 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2371 +  if (!k->oop_is_instance())
  1.2372 +    return 0;
  1.2373 +  return InstanceKlass::cast(k)->methods()->length();
  1.2374 +JVM_END
  1.2375 +
  1.2376 +
  1.2377 +// The following methods, used for the verifier, are never called with
  1.2378 +// array klasses, so a direct cast to InstanceKlass is safe.
  1.2379 +// Typically, these methods are called in a loop with bounds determined
  1.2380 +// by the results of JVM_GetClass{Fields,Methods}Count, which return
  1.2381 +// zero for arrays.
  1.2382 +JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
  1.2383 +  JVMWrapper("JVM_GetMethodIxExceptionIndexes");
  1.2384 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2385 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2386 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2387 +  int length = method->checked_exceptions_length();
  1.2388 +  if (length > 0) {
  1.2389 +    CheckedExceptionElement* table= method->checked_exceptions_start();
  1.2390 +    for (int i = 0; i < length; i++) {
  1.2391 +      exceptions[i] = table[i].class_cp_index;
  1.2392 +    }
  1.2393 +  }
  1.2394 +JVM_END
  1.2395 +
  1.2396 +
  1.2397 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
  1.2398 +  JVMWrapper("JVM_GetMethodIxExceptionsCount");
  1.2399 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2400 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2401 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2402 +  return method->checked_exceptions_length();
  1.2403 +JVM_END
  1.2404 +
  1.2405 +
  1.2406 +JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
  1.2407 +  JVMWrapper("JVM_GetMethodIxByteCode");
  1.2408 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2409 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2410 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2411 +  memcpy(code, method->code_base(), method->code_size());
  1.2412 +JVM_END
  1.2413 +
  1.2414 +
  1.2415 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
  1.2416 +  JVMWrapper("JVM_GetMethodIxByteCodeLength");
  1.2417 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2418 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2419 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2420 +  return method->code_size();
  1.2421 +JVM_END
  1.2422 +
  1.2423 +
  1.2424 +JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
  1.2425 +  JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
  1.2426 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2427 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2428 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2429 +  ExceptionTable extable(method);
  1.2430 +  entry->start_pc   = extable.start_pc(entry_index);
  1.2431 +  entry->end_pc     = extable.end_pc(entry_index);
  1.2432 +  entry->handler_pc = extable.handler_pc(entry_index);
  1.2433 +  entry->catchType  = extable.catch_type_index(entry_index);
  1.2434 +JVM_END
  1.2435 +
  1.2436 +
  1.2437 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
  1.2438 +  JVMWrapper("JVM_GetMethodIxExceptionTableLength");
  1.2439 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2440 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2441 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2442 +  return method->exception_table_length();
  1.2443 +JVM_END
  1.2444 +
  1.2445 +
  1.2446 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
  1.2447 +  JVMWrapper("JVM_GetMethodIxModifiers");
  1.2448 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2449 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2450 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2451 +  return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
  1.2452 +JVM_END
  1.2453 +
  1.2454 +
  1.2455 +JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
  1.2456 +  JVMWrapper("JVM_GetFieldIxModifiers");
  1.2457 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2458 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2459 +  return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
  1.2460 +JVM_END
  1.2461 +
  1.2462 +
  1.2463 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
  1.2464 +  JVMWrapper("JVM_GetMethodIxLocalsCount");
  1.2465 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2466 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2467 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2468 +  return method->max_locals();
  1.2469 +JVM_END
  1.2470 +
  1.2471 +
  1.2472 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
  1.2473 +  JVMWrapper("JVM_GetMethodIxArgsSize");
  1.2474 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2475 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2476 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2477 +  return method->size_of_parameters();
  1.2478 +JVM_END
  1.2479 +
  1.2480 +
  1.2481 +JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
  1.2482 +  JVMWrapper("JVM_GetMethodIxMaxStack");
  1.2483 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2484 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2485 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2486 +  return method->verifier_max_stack();
  1.2487 +JVM_END
  1.2488 +
  1.2489 +
  1.2490 +JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
  1.2491 +  JVMWrapper("JVM_IsConstructorIx");
  1.2492 +  ResourceMark rm(THREAD);
  1.2493 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2494 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2495 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2496 +  return method->name() == vmSymbols::object_initializer_name();
  1.2497 +JVM_END
  1.2498 +
  1.2499 +
  1.2500 +JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
  1.2501 +  JVMWrapper("JVM_IsVMGeneratedMethodIx");
  1.2502 +  ResourceMark rm(THREAD);
  1.2503 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2504 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2505 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2506 +  return method->is_overpass();
  1.2507 +JVM_END
  1.2508 +
  1.2509 +JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
  1.2510 +  JVMWrapper("JVM_GetMethodIxIxUTF");
  1.2511 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2512 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2513 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2514 +  return method->name()->as_utf8();
  1.2515 +JVM_END
  1.2516 +
  1.2517 +
  1.2518 +JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
  1.2519 +  JVMWrapper("JVM_GetMethodIxSignatureUTF");
  1.2520 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2521 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2522 +  Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
  1.2523 +  return method->signature()->as_utf8();
  1.2524 +JVM_END
  1.2525 +
  1.2526 +/**
  1.2527 + * All of these JVM_GetCP-xxx methods are used by the old verifier to
  1.2528 + * read entries in the constant pool.  Since the old verifier always
  1.2529 + * works on a copy of the code, it will not see any rewriting that
  1.2530 + * may possibly occur in the middle of verification.  So it is important
  1.2531 + * that nothing it calls tries to use the cpCache instead of the raw
  1.2532 + * constant pool, so we must use cp->uncached_x methods when appropriate.
  1.2533 + */
  1.2534 +JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2535 +  JVMWrapper("JVM_GetCPFieldNameUTF");
  1.2536 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2537 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2538 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2539 +  switch (cp->tag_at(cp_index).value()) {
  1.2540 +    case JVM_CONSTANT_Fieldref:
  1.2541 +      return cp->uncached_name_ref_at(cp_index)->as_utf8();
  1.2542 +    default:
  1.2543 +      fatal("JVM_GetCPFieldNameUTF: illegal constant");
  1.2544 +  }
  1.2545 +  ShouldNotReachHere();
  1.2546 +  return NULL;
  1.2547 +JVM_END
  1.2548 +
  1.2549 +
  1.2550 +JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2551 +  JVMWrapper("JVM_GetCPMethodNameUTF");
  1.2552 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2553 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2554 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2555 +  switch (cp->tag_at(cp_index).value()) {
  1.2556 +    case JVM_CONSTANT_InterfaceMethodref:
  1.2557 +    case JVM_CONSTANT_Methodref:
  1.2558 +    case JVM_CONSTANT_NameAndType:  // for invokedynamic
  1.2559 +      return cp->uncached_name_ref_at(cp_index)->as_utf8();
  1.2560 +    default:
  1.2561 +      fatal("JVM_GetCPMethodNameUTF: illegal constant");
  1.2562 +  }
  1.2563 +  ShouldNotReachHere();
  1.2564 +  return NULL;
  1.2565 +JVM_END
  1.2566 +
  1.2567 +
  1.2568 +JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2569 +  JVMWrapper("JVM_GetCPMethodSignatureUTF");
  1.2570 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2571 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2572 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2573 +  switch (cp->tag_at(cp_index).value()) {
  1.2574 +    case JVM_CONSTANT_InterfaceMethodref:
  1.2575 +    case JVM_CONSTANT_Methodref:
  1.2576 +    case JVM_CONSTANT_NameAndType:  // for invokedynamic
  1.2577 +      return cp->uncached_signature_ref_at(cp_index)->as_utf8();
  1.2578 +    default:
  1.2579 +      fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
  1.2580 +  }
  1.2581 +  ShouldNotReachHere();
  1.2582 +  return NULL;
  1.2583 +JVM_END
  1.2584 +
  1.2585 +
  1.2586 +JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2587 +  JVMWrapper("JVM_GetCPFieldSignatureUTF");
  1.2588 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2589 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2590 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2591 +  switch (cp->tag_at(cp_index).value()) {
  1.2592 +    case JVM_CONSTANT_Fieldref:
  1.2593 +      return cp->uncached_signature_ref_at(cp_index)->as_utf8();
  1.2594 +    default:
  1.2595 +      fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
  1.2596 +  }
  1.2597 +  ShouldNotReachHere();
  1.2598 +  return NULL;
  1.2599 +JVM_END
  1.2600 +
  1.2601 +
  1.2602 +JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2603 +  JVMWrapper("JVM_GetCPClassNameUTF");
  1.2604 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2605 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2606 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2607 +  Symbol* classname = cp->klass_name_at(cp_index);
  1.2608 +  return classname->as_utf8();
  1.2609 +JVM_END
  1.2610 +
  1.2611 +
  1.2612 +JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2613 +  JVMWrapper("JVM_GetCPFieldClassNameUTF");
  1.2614 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2615 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2616 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2617 +  switch (cp->tag_at(cp_index).value()) {
  1.2618 +    case JVM_CONSTANT_Fieldref: {
  1.2619 +      int class_index = cp->uncached_klass_ref_index_at(cp_index);
  1.2620 +      Symbol* classname = cp->klass_name_at(class_index);
  1.2621 +      return classname->as_utf8();
  1.2622 +    }
  1.2623 +    default:
  1.2624 +      fatal("JVM_GetCPFieldClassNameUTF: illegal constant");
  1.2625 +  }
  1.2626 +  ShouldNotReachHere();
  1.2627 +  return NULL;
  1.2628 +JVM_END
  1.2629 +
  1.2630 +
  1.2631 +JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
  1.2632 +  JVMWrapper("JVM_GetCPMethodClassNameUTF");
  1.2633 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2634 +  k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2635 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2636 +  switch (cp->tag_at(cp_index).value()) {
  1.2637 +    case JVM_CONSTANT_Methodref:
  1.2638 +    case JVM_CONSTANT_InterfaceMethodref: {
  1.2639 +      int class_index = cp->uncached_klass_ref_index_at(cp_index);
  1.2640 +      Symbol* classname = cp->klass_name_at(class_index);
  1.2641 +      return classname->as_utf8();
  1.2642 +    }
  1.2643 +    default:
  1.2644 +      fatal("JVM_GetCPMethodClassNameUTF: illegal constant");
  1.2645 +  }
  1.2646 +  ShouldNotReachHere();
  1.2647 +  return NULL;
  1.2648 +JVM_END
  1.2649 +
  1.2650 +
  1.2651 +JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
  1.2652 +  JVMWrapper("JVM_GetCPFieldModifiers");
  1.2653 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2654 +  Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
  1.2655 +  k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2656 +  k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
  1.2657 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2658 +  ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants();
  1.2659 +  switch (cp->tag_at(cp_index).value()) {
  1.2660 +    case JVM_CONSTANT_Fieldref: {
  1.2661 +      Symbol* name      = cp->uncached_name_ref_at(cp_index);
  1.2662 +      Symbol* signature = cp->uncached_signature_ref_at(cp_index);
  1.2663 +      for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) {
  1.2664 +        if (fs.name() == name && fs.signature() == signature) {
  1.2665 +          return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS;
  1.2666 +        }
  1.2667 +      }
  1.2668 +      return -1;
  1.2669 +    }
  1.2670 +    default:
  1.2671 +      fatal("JVM_GetCPFieldModifiers: illegal constant");
  1.2672 +  }
  1.2673 +  ShouldNotReachHere();
  1.2674 +  return 0;
  1.2675 +JVM_END
  1.2676 +
  1.2677 +
  1.2678 +JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
  1.2679 +  JVMWrapper("JVM_GetCPMethodModifiers");
  1.2680 +  Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
  1.2681 +  Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
  1.2682 +  k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
  1.2683 +  k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
  1.2684 +  ConstantPool* cp = InstanceKlass::cast(k)->constants();
  1.2685 +  switch (cp->tag_at(cp_index).value()) {
  1.2686 +    case JVM_CONSTANT_Methodref:
  1.2687 +    case JVM_CONSTANT_InterfaceMethodref: {
  1.2688 +      Symbol* name      = cp->uncached_name_ref_at(cp_index);
  1.2689 +      Symbol* signature = cp->uncached_signature_ref_at(cp_index);
  1.2690 +      Array<Method*>* methods = InstanceKlass::cast(k_called)->methods();
  1.2691 +      int methods_count = methods->length();
  1.2692 +      for (int i = 0; i < methods_count; i++) {
  1.2693 +        Method* method = methods->at(i);
  1.2694 +        if (method->name() == name && method->signature() == signature) {
  1.2695 +            return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
  1.2696 +        }
  1.2697 +      }
  1.2698 +      return -1;
  1.2699 +    }
  1.2700 +    default:
  1.2701 +      fatal("JVM_GetCPMethodModifiers: illegal constant");
  1.2702 +  }
  1.2703 +  ShouldNotReachHere();
  1.2704 +  return 0;
  1.2705 +JVM_END
  1.2706 +
  1.2707 +
  1.2708 +// Misc //////////////////////////////////////////////////////////////////////////////////////////////
  1.2709 +
  1.2710 +JVM_LEAF(void, JVM_ReleaseUTF(const char *utf))
  1.2711 +  // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything
  1.2712 +JVM_END
  1.2713 +
  1.2714 +
  1.2715 +JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2))
  1.2716 +  JVMWrapper("JVM_IsSameClassPackage");
  1.2717 +  oop class1_mirror = JNIHandles::resolve_non_null(class1);
  1.2718 +  oop class2_mirror = JNIHandles::resolve_non_null(class2);
  1.2719 +  Klass* klass1 = java_lang_Class::as_Klass(class1_mirror);
  1.2720 +  Klass* klass2 = java_lang_Class::as_Klass(class2_mirror);
  1.2721 +  return (jboolean) Reflection::is_same_class_package(klass1, klass2);
  1.2722 +JVM_END
  1.2723 +
  1.2724 +
  1.2725 +// IO functions ////////////////////////////////////////////////////////////////////////////////////////
  1.2726 +
  1.2727 +JVM_LEAF(jint, JVM_Open(const char *fname, jint flags, jint mode))
  1.2728 +  JVMWrapper2("JVM_Open (%s)", fname);
  1.2729 +
  1.2730 +  //%note jvm_r6
  1.2731 +  int result = os::open(fname, flags, mode);
  1.2732 +  if (result >= 0) {
  1.2733 +    return result;
  1.2734 +  } else {
  1.2735 +    switch(errno) {
  1.2736 +      case EEXIST:
  1.2737 +        return JVM_EEXIST;
  1.2738 +      default:
  1.2739 +        return -1;
  1.2740 +    }
  1.2741 +  }
  1.2742 +JVM_END
  1.2743 +
  1.2744 +
  1.2745 +JVM_LEAF(jint, JVM_Close(jint fd))
  1.2746 +  JVMWrapper2("JVM_Close (0x%x)", fd);
  1.2747 +  //%note jvm_r6
  1.2748 +  return os::close(fd);
  1.2749 +JVM_END
  1.2750 +
  1.2751 +
  1.2752 +JVM_LEAF(jint, JVM_Read(jint fd, char *buf, jint nbytes))
  1.2753 +  JVMWrapper2("JVM_Read (0x%x)", fd);
  1.2754 +
  1.2755 +  //%note jvm_r6
  1.2756 +  return (jint)os::restartable_read(fd, buf, nbytes);
  1.2757 +JVM_END
  1.2758 +
  1.2759 +
  1.2760 +JVM_LEAF(jint, JVM_Write(jint fd, char *buf, jint nbytes))
  1.2761 +  JVMWrapper2("JVM_Write (0x%x)", fd);
  1.2762 +
  1.2763 +  //%note jvm_r6
  1.2764 +  return (jint)os::write(fd, buf, nbytes);
  1.2765 +JVM_END
  1.2766 +
  1.2767 +
  1.2768 +JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes))
  1.2769 +  JVMWrapper2("JVM_Available (0x%x)", fd);
  1.2770 +  //%note jvm_r6
  1.2771 +  return os::available(fd, pbytes);
  1.2772 +JVM_END
  1.2773 +
  1.2774 +
  1.2775 +JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence))
  1.2776 +  JVMWrapper4("JVM_Lseek (0x%x, " INT64_FORMAT ", %d)", fd, (int64_t) offset, whence);
  1.2777 +  //%note jvm_r6
  1.2778 +  return os::lseek(fd, offset, whence);
  1.2779 +JVM_END
  1.2780 +
  1.2781 +
  1.2782 +JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
  1.2783 +  JVMWrapper3("JVM_SetLength (0x%x, " INT64_FORMAT ")", fd, (int64_t) length);
  1.2784 +  return os::ftruncate(fd, length);
  1.2785 +JVM_END
  1.2786 +
  1.2787 +
  1.2788 +JVM_LEAF(jint, JVM_Sync(jint fd))
  1.2789 +  JVMWrapper2("JVM_Sync (0x%x)", fd);
  1.2790 +  //%note jvm_r6
  1.2791 +  return os::fsync(fd);
  1.2792 +JVM_END
  1.2793 +
  1.2794 +
  1.2795 +// Printing support //////////////////////////////////////////////////
  1.2796 +extern "C" {
  1.2797 +
  1.2798 +ATTRIBUTE_PRINTF(3, 0)
  1.2799 +int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
  1.2800 +  // see bug 4399518, 4417214
  1.2801 +  if ((intptr_t)count <= 0) return -1;
  1.2802 +  return vsnprintf(str, count, fmt, args);
  1.2803 +}
  1.2804 +
  1.2805 +ATTRIBUTE_PRINTF(3, 0)
  1.2806 +int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
  1.2807 +  va_list args;
  1.2808 +  int len;
  1.2809 +  va_start(args, fmt);
  1.2810 +  len = jio_vsnprintf(str, count, fmt, args);
  1.2811 +  va_end(args);
  1.2812 +  return len;
  1.2813 +}
  1.2814 +
  1.2815 +ATTRIBUTE_PRINTF(2,3)
  1.2816 +int jio_fprintf(FILE* f, const char *fmt, ...) {
  1.2817 +  int len;
  1.2818 +  va_list args;
  1.2819 +  va_start(args, fmt);
  1.2820 +  len = jio_vfprintf(f, fmt, args);
  1.2821 +  va_end(args);
  1.2822 +  return len;
  1.2823 +}
  1.2824 +
  1.2825 +ATTRIBUTE_PRINTF(2, 0)
  1.2826 +int jio_vfprintf(FILE* f, const char *fmt, va_list args) {
  1.2827 +  if (Arguments::vfprintf_hook() != NULL) {
  1.2828 +     return Arguments::vfprintf_hook()(f, fmt, args);
  1.2829 +  } else {
  1.2830 +    return vfprintf(f, fmt, args);
  1.2831 +  }
  1.2832 +}
  1.2833 +
  1.2834 +ATTRIBUTE_PRINTF(1, 2)
  1.2835 +JNIEXPORT int jio_printf(const char *fmt, ...) {
  1.2836 +  int len;
  1.2837 +  va_list args;
  1.2838 +  va_start(args, fmt);
  1.2839 +  len = jio_vfprintf(defaultStream::output_stream(), fmt, args);
  1.2840 +  va_end(args);
  1.2841 +  return len;
  1.2842 +}
  1.2843 +
  1.2844 +
  1.2845 +// HotSpot specific jio method
  1.2846 +void jio_print(const char* s) {
  1.2847 +  // Try to make this function as atomic as possible.
  1.2848 +  if (Arguments::vfprintf_hook() != NULL) {
  1.2849 +    jio_fprintf(defaultStream::output_stream(), "%s", s);
  1.2850 +  } else {
  1.2851 +    // Make an unused local variable to avoid warning from gcc 4.x compiler.
  1.2852 +    size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s));
  1.2853 +  }
  1.2854 +}
  1.2855 +
  1.2856 +} // Extern C
  1.2857 +
  1.2858 +// java.lang.Thread //////////////////////////////////////////////////////////////////////////////
  1.2859 +
  1.2860 +// In most of the JVM Thread support functions we need to be sure to lock the Threads_lock
  1.2861 +// to prevent the target thread from exiting after we have a pointer to the C++ Thread or
  1.2862 +// OSThread objects.  The exception to this rule is when the target object is the thread
  1.2863 +// doing the operation, in which case we know that the thread won't exit until the
  1.2864 +// operation is done (all exits being voluntary).  There are a few cases where it is
  1.2865 +// rather silly to do operations on yourself, like resuming yourself or asking whether
  1.2866 +// you are alive.  While these can still happen, they are not subject to deadlocks if
  1.2867 +// the lock is held while the operation occurs (this is not the case for suspend, for
  1.2868 +// instance), and are very unlikely.  Because IsAlive needs to be fast and its
  1.2869 +// implementation is local to this file, we always lock Threads_lock for that one.
  1.2870 +
  1.2871 +static void thread_entry(JavaThread* thread, TRAPS) {
  1.2872 +  HandleMark hm(THREAD);
  1.2873 +  Handle obj(THREAD, thread->threadObj());
  1.2874 +  JavaValue result(T_VOID);
  1.2875 +  JavaCalls::call_virtual(&result,
  1.2876 +                          obj,
  1.2877 +                          KlassHandle(THREAD, SystemDictionary::Thread_klass()),
  1.2878 +                          vmSymbols::run_method_name(),
  1.2879 +                          vmSymbols::void_method_signature(),
  1.2880 +                          THREAD);
  1.2881 +}
  1.2882 +
  1.2883 +
  1.2884 +JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
  1.2885 +  JVMWrapper("JVM_StartThread");
  1.2886 +  JavaThread *native_thread = NULL;
  1.2887 +
  1.2888 +  // We cannot hold the Threads_lock when we throw an exception,
  1.2889 +  // due to rank ordering issues. Example:  we might need to grab the
  1.2890 +  // Heap_lock while we construct the exception.
  1.2891 +  bool throw_illegal_thread_state = false;
  1.2892 +
  1.2893 +  // We must release the Threads_lock before we can post a jvmti event
  1.2894 +  // in Thread::start.
  1.2895 +  {
  1.2896 +    // Ensure that the C++ Thread and OSThread structures aren't freed before
  1.2897 +    // we operate.
  1.2898 +    MutexLocker mu(Threads_lock);
  1.2899 +
  1.2900 +    // Since JDK 5 the java.lang.Thread threadStatus is used to prevent
  1.2901 +    // re-starting an already started thread, so we should usually find
  1.2902 +    // that the JavaThread is null. However for a JNI attached thread
  1.2903 +    // there is a small window between the Thread object being created
  1.2904 +    // (with its JavaThread set) and the update to its threadStatus, so we
  1.2905 +    // have to check for this
  1.2906 +    if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) {
  1.2907 +      throw_illegal_thread_state = true;
  1.2908 +    } else {
  1.2909 +      // We could also check the stillborn flag to see if this thread was already stopped, but
  1.2910 +      // for historical reasons we let the thread detect that itself when it starts running
  1.2911 +
  1.2912 +      jlong size =
  1.2913 +             java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread));
  1.2914 +      // Allocate the C++ Thread structure and create the native thread.  The
  1.2915 +      // stack size retrieved from java is signed, but the constructor takes
  1.2916 +      // size_t (an unsigned type), so avoid passing negative values which would
  1.2917 +      // result in really large stacks.
  1.2918 +      size_t sz = size > 0 ? (size_t) size : 0;
  1.2919 +      native_thread = new JavaThread(&thread_entry, sz);
  1.2920 +
  1.2921 +      // At this point it may be possible that no osthread was created for the
  1.2922 +      // JavaThread due to lack of memory. Check for this situation and throw
  1.2923 +      // an exception if necessary. Eventually we may want to change this so
  1.2924 +      // that we only grab the lock if the thread was created successfully -
  1.2925 +      // then we can also do this check and throw the exception in the
  1.2926 +      // JavaThread constructor.
  1.2927 +      if (native_thread->osthread() != NULL) {
  1.2928 +        // Note: the current thread is not being used within "prepare".
  1.2929 +        native_thread->prepare(jthread);
  1.2930 +      }
  1.2931 +    }
  1.2932 +  }
  1.2933 +
  1.2934 +  if (throw_illegal_thread_state) {
  1.2935 +    THROW(vmSymbols::java_lang_IllegalThreadStateException());
  1.2936 +  }
  1.2937 +
  1.2938 +  assert(native_thread != NULL, "Starting null thread?");
  1.2939 +
  1.2940 +  if (native_thread->osthread() == NULL) {
  1.2941 +    // No one should hold a reference to the 'native_thread'.
  1.2942 +    delete native_thread;
  1.2943 +    if (JvmtiExport::should_post_resource_exhausted()) {
  1.2944 +      JvmtiExport::post_resource_exhausted(
  1.2945 +        JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
  1.2946 +        "unable to create new native thread");
  1.2947 +    }
  1.2948 +    THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
  1.2949 +              "unable to create new native thread");
  1.2950 +  }
  1.2951 +
  1.2952 +  Thread::start(native_thread);
  1.2953 +
  1.2954 +JVM_END
  1.2955 +
  1.2956 +// JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
  1.2957 +// before the quasi-asynchronous exception is delivered.  This is a little obtrusive,
  1.2958 +// but is thought to be reliable and simple. In the case, where the receiver is the
  1.2959 +// same thread as the sender, no safepoint is needed.
  1.2960 +JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
  1.2961 +  JVMWrapper("JVM_StopThread");
  1.2962 +
  1.2963 +  oop java_throwable = JNIHandles::resolve(throwable);
  1.2964 +  if (java_throwable == NULL) {
  1.2965 +    THROW(vmSymbols::java_lang_NullPointerException());
  1.2966 +  }
  1.2967 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.2968 +  JavaThread* receiver = java_lang_Thread::thread(java_thread);
  1.2969 +  Events::log_exception(JavaThread::current(),
  1.2970 +                        "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
  1.2971 +                        p2i(receiver), p2i((address)java_thread), p2i(throwable));
  1.2972 +  // First check if thread is alive
  1.2973 +  if (receiver != NULL) {
  1.2974 +    // Check if exception is getting thrown at self (use oop equality, since the
  1.2975 +    // target object might exit)
  1.2976 +    if (java_thread == thread->threadObj()) {
  1.2977 +      THROW_OOP(java_throwable);
  1.2978 +    } else {
  1.2979 +      // Enques a VM_Operation to stop all threads and then deliver the exception...
  1.2980 +      Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable));
  1.2981 +    }
  1.2982 +  }
  1.2983 +  else {
  1.2984 +    // Either:
  1.2985 +    // - target thread has not been started before being stopped, or
  1.2986 +    // - target thread already terminated
  1.2987 +    // We could read the threadStatus to determine which case it is
  1.2988 +    // but that is overkill as it doesn't matter. We must set the
  1.2989 +    // stillborn flag for the first case, and if the thread has already
  1.2990 +    // exited setting this flag has no affect
  1.2991 +    java_lang_Thread::set_stillborn(java_thread);
  1.2992 +  }
  1.2993 +JVM_END
  1.2994 +
  1.2995 +
  1.2996 +JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread))
  1.2997 +  JVMWrapper("JVM_IsThreadAlive");
  1.2998 +
  1.2999 +  oop thread_oop = JNIHandles::resolve_non_null(jthread);
  1.3000 +  return java_lang_Thread::is_alive(thread_oop);
  1.3001 +JVM_END
  1.3002 +
  1.3003 +
  1.3004 +JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread))
  1.3005 +  JVMWrapper("JVM_SuspendThread");
  1.3006 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3007 +  JavaThread* receiver = java_lang_Thread::thread(java_thread);
  1.3008 +
  1.3009 +  if (receiver != NULL) {
  1.3010 +    // thread has run and has not exited (still on threads list)
  1.3011 +
  1.3012 +    {
  1.3013 +      MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag);
  1.3014 +      if (receiver->is_external_suspend()) {
  1.3015 +        // Don't allow nested external suspend requests. We can't return
  1.3016 +        // an error from this interface so just ignore the problem.
  1.3017 +        return;
  1.3018 +      }
  1.3019 +      if (receiver->is_exiting()) { // thread is in the process of exiting
  1.3020 +        return;
  1.3021 +      }
  1.3022 +      receiver->set_external_suspend();
  1.3023 +    }
  1.3024 +
  1.3025 +    // java_suspend() will catch threads in the process of exiting
  1.3026 +    // and will ignore them.
  1.3027 +    receiver->java_suspend();
  1.3028 +
  1.3029 +    // It would be nice to have the following assertion in all the
  1.3030 +    // time, but it is possible for a racing resume request to have
  1.3031 +    // resumed this thread right after we suspended it. Temporarily
  1.3032 +    // enable this assertion if you are chasing a different kind of
  1.3033 +    // bug.
  1.3034 +    //
  1.3035 +    // assert(java_lang_Thread::thread(receiver->threadObj()) == NULL ||
  1.3036 +    //   receiver->is_being_ext_suspended(), "thread is not suspended");
  1.3037 +  }
  1.3038 +JVM_END
  1.3039 +
  1.3040 +
  1.3041 +JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread))
  1.3042 +  JVMWrapper("JVM_ResumeThread");
  1.3043 +  // Ensure that the C++ Thread and OSThread structures aren't freed before we operate.
  1.3044 +  // We need to *always* get the threads lock here, since this operation cannot be allowed during
  1.3045 +  // a safepoint. The safepoint code relies on suspending a thread to examine its state. If other
  1.3046 +  // threads randomly resumes threads, then a thread might not be suspended when the safepoint code
  1.3047 +  // looks at it.
  1.3048 +  MutexLocker ml(Threads_lock);
  1.3049 +  JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
  1.3050 +  if (thr != NULL) {
  1.3051 +    // the thread has run and is not in the process of exiting
  1.3052 +    thr->java_resume();
  1.3053 +  }
  1.3054 +JVM_END
  1.3055 +
  1.3056 +
  1.3057 +JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio))
  1.3058 +  JVMWrapper("JVM_SetThreadPriority");
  1.3059 +  // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
  1.3060 +  MutexLocker ml(Threads_lock);
  1.3061 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3062 +  java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
  1.3063 +  JavaThread* thr = java_lang_Thread::thread(java_thread);
  1.3064 +  if (thr != NULL) {                  // Thread not yet started; priority pushed down when it is
  1.3065 +    Thread::set_priority(thr, (ThreadPriority)prio);
  1.3066 +  }
  1.3067 +JVM_END
  1.3068 +
  1.3069 +
  1.3070 +JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
  1.3071 +  JVMWrapper("JVM_Yield");
  1.3072 +  if (os::dont_yield()) return;
  1.3073 +#ifndef USDT2
  1.3074 +  HS_DTRACE_PROBE0(hotspot, thread__yield);
  1.3075 +#else /* USDT2 */
  1.3076 +  HOTSPOT_THREAD_YIELD();
  1.3077 +#endif /* USDT2 */
  1.3078 +  // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
  1.3079 +  // Critical for similar threading behaviour
  1.3080 +  if (ConvertYieldToSleep) {
  1.3081 +    os::sleep(thread, MinSleepInterval, false);
  1.3082 +  } else {
  1.3083 +    os::yield();
  1.3084 +  }
  1.3085 +JVM_END
  1.3086 +
  1.3087 +
  1.3088 +JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
  1.3089 +  JVMWrapper("JVM_Sleep");
  1.3090 +
  1.3091 +  if (millis < 0) {
  1.3092 +    THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
  1.3093 +  }
  1.3094 +
  1.3095 +  if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
  1.3096 +    THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  1.3097 +  }
  1.3098 +
  1.3099 +  // Save current thread state and restore it at the end of this block.
  1.3100 +  // And set new thread state to SLEEPING.
  1.3101 +  JavaThreadSleepState jtss(thread);
  1.3102 +
  1.3103 +#ifndef USDT2
  1.3104 +  HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
  1.3105 +#else /* USDT2 */
  1.3106 +  HOTSPOT_THREAD_SLEEP_BEGIN(
  1.3107 +                             millis);
  1.3108 +#endif /* USDT2 */
  1.3109 +
  1.3110 +  EventThreadSleep event;
  1.3111 +
  1.3112 +  if (millis == 0) {
  1.3113 +    // When ConvertSleepToYield is on, this matches the classic VM implementation of
  1.3114 +    // JVM_Sleep. Critical for similar threading behaviour (Win32)
  1.3115 +    // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
  1.3116 +    // for SOLARIS
  1.3117 +    if (ConvertSleepToYield) {
  1.3118 +      os::yield();
  1.3119 +    } else {
  1.3120 +      ThreadState old_state = thread->osthread()->get_state();
  1.3121 +      thread->osthread()->set_state(SLEEPING);
  1.3122 +      os::sleep(thread, MinSleepInterval, false);
  1.3123 +      thread->osthread()->set_state(old_state);
  1.3124 +    }
  1.3125 +  } else {
  1.3126 +    ThreadState old_state = thread->osthread()->get_state();
  1.3127 +    thread->osthread()->set_state(SLEEPING);
  1.3128 +    if (os::sleep(thread, millis, true) == OS_INTRPT) {
  1.3129 +      // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
  1.3130 +      // us while we were sleeping. We do not overwrite those.
  1.3131 +      if (!HAS_PENDING_EXCEPTION) {
  1.3132 +        if (event.should_commit()) {
  1.3133 +          event.set_time(millis);
  1.3134 +          event.commit();
  1.3135 +        }
  1.3136 +#ifndef USDT2
  1.3137 +        HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
  1.3138 +#else /* USDT2 */
  1.3139 +        HOTSPOT_THREAD_SLEEP_END(
  1.3140 +                                 1);
  1.3141 +#endif /* USDT2 */
  1.3142 +        // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
  1.3143 +        // to properly restore the thread state.  That's likely wrong.
  1.3144 +        THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
  1.3145 +      }
  1.3146 +    }
  1.3147 +    thread->osthread()->set_state(old_state);
  1.3148 +  }
  1.3149 +  if (event.should_commit()) {
  1.3150 +    event.set_time(millis);
  1.3151 +    event.commit();
  1.3152 +  }
  1.3153 +#ifndef USDT2
  1.3154 +  HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
  1.3155 +#else /* USDT2 */
  1.3156 +  HOTSPOT_THREAD_SLEEP_END(
  1.3157 +                           0);
  1.3158 +#endif /* USDT2 */
  1.3159 +JVM_END
  1.3160 +
  1.3161 +JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
  1.3162 +  JVMWrapper("JVM_CurrentThread");
  1.3163 +  oop jthread = thread->threadObj();
  1.3164 +  assert (thread != NULL, "no current thread!");
  1.3165 +  return JNIHandles::make_local(env, jthread);
  1.3166 +JVM_END
  1.3167 +
  1.3168 +
  1.3169 +JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
  1.3170 +  JVMWrapper("JVM_CountStackFrames");
  1.3171 +
  1.3172 +  // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
  1.3173 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3174 +  bool throw_illegal_thread_state = false;
  1.3175 +  int count = 0;
  1.3176 +
  1.3177 +  {
  1.3178 +    MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
  1.3179 +    // We need to re-resolve the java_thread, since a GC might have happened during the
  1.3180 +    // acquire of the lock
  1.3181 +    JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
  1.3182 +
  1.3183 +    if (thr == NULL) {
  1.3184 +      // do nothing
  1.3185 +    } else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) {
  1.3186 +      // Check whether this java thread has been suspended already. If not, throws
  1.3187 +      // IllegalThreadStateException. We defer to throw that exception until
  1.3188 +      // Threads_lock is released since loading exception class has to leave VM.
  1.3189 +      // The correct way to test a thread is actually suspended is
  1.3190 +      // wait_for_ext_suspend_completion(), but we can't call that while holding
  1.3191 +      // the Threads_lock. The above tests are sufficient for our purposes
  1.3192 +      // provided the walkability of the stack is stable - which it isn't
  1.3193 +      // 100% but close enough for most practical purposes.
  1.3194 +      throw_illegal_thread_state = true;
  1.3195 +    } else {
  1.3196 +      // Count all java activation, i.e., number of vframes
  1.3197 +      for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) {
  1.3198 +        // Native frames are not counted
  1.3199 +        if (!vfst.method()->is_native()) count++;
  1.3200 +       }
  1.3201 +    }
  1.3202 +  }
  1.3203 +
  1.3204 +  if (throw_illegal_thread_state) {
  1.3205 +    THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(),
  1.3206 +                "this thread is not suspended");
  1.3207 +  }
  1.3208 +  return count;
  1.3209 +JVM_END
  1.3210 +
  1.3211 +// Consider: A better way to implement JVM_Interrupt() is to acquire
  1.3212 +// Threads_lock to resolve the jthread into a Thread pointer, fetch
  1.3213 +// Thread->platformevent, Thread->native_thr, Thread->parker, etc.,
  1.3214 +// drop Threads_lock, and the perform the unpark() and thr_kill() operations
  1.3215 +// outside the critical section.  Threads_lock is hot so we want to minimize
  1.3216 +// the hold-time.  A cleaner interface would be to decompose interrupt into
  1.3217 +// two steps.  The 1st phase, performed under Threads_lock, would return
  1.3218 +// a closure that'd be invoked after Threads_lock was dropped.
  1.3219 +// This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and
  1.3220 +// admit spurious wakeups.
  1.3221 +
  1.3222 +JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
  1.3223 +  JVMWrapper("JVM_Interrupt");
  1.3224 +
  1.3225 +  // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
  1.3226 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3227 +  MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
  1.3228 +  // We need to re-resolve the java_thread, since a GC might have happened during the
  1.3229 +  // acquire of the lock
  1.3230 +  JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
  1.3231 +  if (thr != NULL) {
  1.3232 +    Thread::interrupt(thr);
  1.3233 +  }
  1.3234 +JVM_END
  1.3235 +
  1.3236 +
  1.3237 +JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
  1.3238 +  JVMWrapper("JVM_IsInterrupted");
  1.3239 +
  1.3240 +  // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
  1.3241 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3242 +  MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
  1.3243 +  // We need to re-resolve the java_thread, since a GC might have happened during the
  1.3244 +  // acquire of the lock
  1.3245 +  JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
  1.3246 +  if (thr == NULL) {
  1.3247 +    return JNI_FALSE;
  1.3248 +  } else {
  1.3249 +    return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
  1.3250 +  }
  1.3251 +JVM_END
  1.3252 +
  1.3253 +
  1.3254 +// Return true iff the current thread has locked the object passed in
  1.3255 +
  1.3256 +JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
  1.3257 +  JVMWrapper("JVM_HoldsLock");
  1.3258 +  assert(THREAD->is_Java_thread(), "sanity check");
  1.3259 +  if (obj == NULL) {
  1.3260 +    THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
  1.3261 +  }
  1.3262 +  Handle h_obj(THREAD, JNIHandles::resolve(obj));
  1.3263 +  return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
  1.3264 +JVM_END
  1.3265 +
  1.3266 +
  1.3267 +JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
  1.3268 +  JVMWrapper("JVM_DumpAllStacks");
  1.3269 +  VM_PrintThreads op;
  1.3270 +  VMThread::execute(&op);
  1.3271 +  if (JvmtiExport::should_post_data_dump()) {
  1.3272 +    JvmtiExport::post_data_dump();
  1.3273 +  }
  1.3274 +JVM_END
  1.3275 +
  1.3276 +JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
  1.3277 +  JVMWrapper("JVM_SetNativeThreadName");
  1.3278 +  ResourceMark rm(THREAD);
  1.3279 +  oop java_thread = JNIHandles::resolve_non_null(jthread);
  1.3280 +  JavaThread* thr = java_lang_Thread::thread(java_thread);
  1.3281 +  // Thread naming only supported for the current thread, doesn't work for
  1.3282 +  // target threads.
  1.3283 +  if (Thread::current() == thr && !thr->has_attached_via_jni()) {
  1.3284 +    // we don't set the name of an attached thread to avoid stepping
  1.3285 +    // on other programs
  1.3286 +    const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
  1.3287 +    os::set_native_thread_name(thread_name);
  1.3288 +  }
  1.3289 +JVM_END
  1.3290 +
  1.3291 +// java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
  1.3292 +
  1.3293 +static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
  1.3294 +  assert(jthread->is_Java_thread(), "must be a Java thread");
  1.3295 +  if (jthread->privileged_stack_top() == NULL) return false;
  1.3296 +  if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) {
  1.3297 +    oop loader = jthread->privileged_stack_top()->class_loader();
  1.3298 +    if (loader == NULL) return true;
  1.3299 +    bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
  1.3300 +    if (trusted) return true;
  1.3301 +  }
  1.3302 +  return false;
  1.3303 +}
  1.3304 +
  1.3305 +JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env))
  1.3306 +  JVMWrapper("JVM_CurrentLoadedClass");
  1.3307 +  ResourceMark rm(THREAD);
  1.3308 +
  1.3309 +  for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
  1.3310 +    // if a method in a class in a trusted loader is in a doPrivileged, return NULL
  1.3311 +    bool trusted = is_trusted_frame(thread, &vfst);
  1.3312 +    if (trusted) return NULL;
  1.3313 +
  1.3314 +    Method* m = vfst.method();
  1.3315 +    if (!m->is_native()) {
  1.3316 +      InstanceKlass* holder = m->method_holder();
  1.3317 +      oop loader = holder->class_loader();
  1.3318 +      if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
  1.3319 +        return (jclass) JNIHandles::make_local(env, holder->java_mirror());
  1.3320 +      }
  1.3321 +    }
  1.3322 +  }
  1.3323 +  return NULL;
  1.3324 +JVM_END
  1.3325 +
  1.3326 +
  1.3327 +JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env))
  1.3328 +  JVMWrapper("JVM_CurrentClassLoader");
  1.3329 +  ResourceMark rm(THREAD);
  1.3330 +
  1.3331 +  for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
  1.3332 +
  1.3333 +    // if a method in a class in a trusted loader is in a doPrivileged, return NULL
  1.3334 +    bool trusted = is_trusted_frame(thread, &vfst);
  1.3335 +    if (trusted) return NULL;
  1.3336 +
  1.3337 +    Method* m = vfst.method();
  1.3338 +    if (!m->is_native()) {
  1.3339 +      InstanceKlass* holder = m->method_holder();
  1.3340 +      assert(holder->is_klass(), "just checking");
  1.3341 +      oop loader = holder->class_loader();
  1.3342 +      if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
  1.3343 +        return JNIHandles::make_local(env, loader);
  1.3344 +      }
  1.3345 +    }
  1.3346 +  }
  1.3347 +  return NULL;
  1.3348 +JVM_END
  1.3349 +
  1.3350 +
  1.3351 +JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
  1.3352 +  JVMWrapper("JVM_GetClassContext");
  1.3353 +  ResourceMark rm(THREAD);
  1.3354 +  JvmtiVMObjectAllocEventCollector oam;
  1.3355 +  vframeStream vfst(thread);
  1.3356 +
  1.3357 +  if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) {
  1.3358 +    // This must only be called from SecurityManager.getClassContext
  1.3359 +    Method* m = vfst.method();
  1.3360 +    if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() &&
  1.3361 +          m->name()          == vmSymbols::getClassContext_name() &&
  1.3362 +          m->signature()     == vmSymbols::void_class_array_signature())) {
  1.3363 +      THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
  1.3364 +    }
  1.3365 +  }
  1.3366 +
  1.3367 +  // Collect method holders
  1.3368 +  GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>();
  1.3369 +  for (; !vfst.at_end(); vfst.security_next()) {
  1.3370 +    Method* m = vfst.method();
  1.3371 +    // Native frames are not returned
  1.3372 +    if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) {
  1.3373 +      Klass* holder = m->method_holder();
  1.3374 +      assert(holder->is_klass(), "just checking");
  1.3375 +      klass_array->append(holder);
  1.3376 +    }
  1.3377 +  }
  1.3378 +
  1.3379 +  // Create result array of type [Ljava/lang/Class;
  1.3380 +  objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL);
  1.3381 +  // Fill in mirrors corresponding to method holders
  1.3382 +  for (int i = 0; i < klass_array->length(); i++) {
  1.3383 +    result->obj_at_put(i, klass_array->at(i)->java_mirror());
  1.3384 +  }
  1.3385 +
  1.3386 +  return (jobjectArray) JNIHandles::make_local(env, result);
  1.3387 +JVM_END
  1.3388 +
  1.3389 +
  1.3390 +JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name))
  1.3391 +  JVMWrapper("JVM_ClassDepth");
  1.3392 +  ResourceMark rm(THREAD);
  1.3393 +  Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
  1.3394 +  Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0);
  1.3395 +
  1.3396 +  const char* str = java_lang_String::as_utf8_string(class_name_str());
  1.3397 +  TempNewSymbol class_name_sym = SymbolTable::probe(str, (int)strlen(str));
  1.3398 +  if (class_name_sym == NULL) {
  1.3399 +    return -1;
  1.3400 +  }
  1.3401 +
  1.3402 +  int depth = 0;
  1.3403 +
  1.3404 +  for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
  1.3405 +    if (!vfst.method()->is_native()) {
  1.3406 +      InstanceKlass* holder = vfst.method()->method_holder();
  1.3407 +      assert(holder->is_klass(), "just checking");
  1.3408 +      if (holder->name() == class_name_sym) {
  1.3409 +        return depth;
  1.3410 +      }
  1.3411 +      depth++;
  1.3412 +    }
  1.3413 +  }
  1.3414 +  return -1;
  1.3415 +JVM_END
  1.3416 +
  1.3417 +
  1.3418 +JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env))
  1.3419 +  JVMWrapper("JVM_ClassLoaderDepth");
  1.3420 +  ResourceMark rm(THREAD);
  1.3421 +  int depth = 0;
  1.3422 +  for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
  1.3423 +    // if a method in a class in a trusted loader is in a doPrivileged, return -1
  1.3424 +    bool trusted = is_trusted_frame(thread, &vfst);
  1.3425 +    if (trusted) return -1;
  1.3426 +
  1.3427 +    Method* m = vfst.method();
  1.3428 +    if (!m->is_native()) {
  1.3429 +      InstanceKlass* holder = m->method_holder();
  1.3430 +      assert(holder->is_klass(), "just checking");
  1.3431 +      oop loader = holder->class_loader();
  1.3432 +      if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
  1.3433 +        return depth;
  1.3434 +      }
  1.3435 +      depth++;
  1.3436 +    }
  1.3437 +  }
  1.3438 +  return -1;
  1.3439 +JVM_END
  1.3440 +
  1.3441 +
  1.3442 +// java.lang.Package ////////////////////////////////////////////////////////////////
  1.3443 +
  1.3444 +
  1.3445 +JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
  1.3446 +  JVMWrapper("JVM_GetSystemPackage");
  1.3447 +  ResourceMark rm(THREAD);
  1.3448 +  JvmtiVMObjectAllocEventCollector oam;
  1.3449 +  char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
  1.3450 +  oop result = ClassLoader::get_system_package(str, CHECK_NULL);
  1.3451 +  return (jstring) JNIHandles::make_local(result);
  1.3452 +JVM_END
  1.3453 +
  1.3454 +
  1.3455 +JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
  1.3456 +  JVMWrapper("JVM_GetSystemPackages");
  1.3457 +  JvmtiVMObjectAllocEventCollector oam;
  1.3458 +  objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
  1.3459 +  return (jobjectArray) JNIHandles::make_local(result);
  1.3460 +JVM_END
  1.3461 +
  1.3462 +
  1.3463 +// ObjectInputStream ///////////////////////////////////////////////////////////////
  1.3464 +
  1.3465 +bool force_verify_field_access(Klass* current_class, Klass* field_class, AccessFlags access, bool classloader_only) {
  1.3466 +  if (current_class == NULL) {
  1.3467 +    return true;
  1.3468 +  }
  1.3469 +  if ((current_class == field_class) || access.is_public()) {
  1.3470 +    return true;
  1.3471 +  }
  1.3472 +
  1.3473 +  if (access.is_protected()) {
  1.3474 +    // See if current_class is a subclass of field_class
  1.3475 +    if (current_class->is_subclass_of(field_class)) {
  1.3476 +      return true;
  1.3477 +    }
  1.3478 +  }
  1.3479 +
  1.3480 +  return (!access.is_private() && InstanceKlass::cast(current_class)->is_same_class_package(field_class));
  1.3481 +}
  1.3482 +
  1.3483 +
  1.3484 +// JVM_AllocateNewObject and JVM_AllocateNewArray are unused as of 1.4
  1.3485 +JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass))
  1.3486 +  JVMWrapper("JVM_AllocateNewObject");
  1.3487 +  JvmtiVMObjectAllocEventCollector oam;
  1.3488 +  // Receiver is not used
  1.3489 +  oop curr_mirror = JNIHandles::resolve_non_null(currClass);
  1.3490 +  oop init_mirror = JNIHandles::resolve_non_null(initClass);
  1.3491 +
  1.3492 +  // Cannot instantiate primitive types
  1.3493 +  if (java_lang_Class::is_primitive(curr_mirror) || java_lang_Class::is_primitive(init_mirror)) {
  1.3494 +    ResourceMark rm(THREAD);
  1.3495 +    THROW_0(vmSymbols::java_lang_InvalidClassException());
  1.3496 +  }
  1.3497 +
  1.3498 +  // Arrays not allowed here, must use JVM_AllocateNewArray
  1.3499 +  if (java_lang_Class::as_Klass(curr_mirror)->oop_is_array() ||
  1.3500 +      java_lang_Class::as_Klass(init_mirror)->oop_is_array()) {
  1.3501 +    ResourceMark rm(THREAD);
  1.3502 +    THROW_0(vmSymbols::java_lang_InvalidClassException());
  1.3503 +  }
  1.3504 +
  1.3505 +  instanceKlassHandle curr_klass (THREAD, java_lang_Class::as_Klass(curr_mirror));
  1.3506 +  instanceKlassHandle init_klass (THREAD, java_lang_Class::as_Klass(init_mirror));
  1.3507 +
  1.3508 +  assert(curr_klass->is_subclass_of(init_klass()), "just checking");
  1.3509 +
  1.3510 +  // Interfaces, abstract classes, and java.lang.Class classes cannot be instantiated directly.
  1.3511 +  curr_klass->check_valid_for_instantiation(false, CHECK_NULL);
  1.3512 +
  1.3513 +  // Make sure klass is initialized, since we are about to instantiate one of them.
  1.3514 +  curr_klass->initialize(CHECK_NULL);
  1.3515 +
  1.3516 + methodHandle m (THREAD,
  1.3517 +                 init_klass->find_method(vmSymbols::object_initializer_name(),
  1.3518 +                                         vmSymbols::void_method_signature()));
  1.3519 +  if (m.is_null()) {
  1.3520 +    ResourceMark rm(THREAD);
  1.3521 +    THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(),
  1.3522 +                Method::name_and_sig_as_C_string(init_klass(),
  1.3523 +                                          vmSymbols::object_initializer_name(),
  1.3524 +                                          vmSymbols::void_method_signature()));
  1.3525 +  }
  1.3526 +
  1.3527 +  if (curr_klass ==  init_klass && !m->is_public()) {
  1.3528 +    // Calling the constructor for class 'curr_klass'.
  1.3529 +    // Only allow calls to a public no-arg constructor.
  1.3530 +    // This path corresponds to creating an Externalizable object.
  1.3531 +    THROW_0(vmSymbols::java_lang_IllegalAccessException());
  1.3532 +  }
  1.3533 +
  1.3534 +  if (!force_verify_field_access(curr_klass(), init_klass(), m->access_flags(), false)) {
  1.3535 +    // subclass 'curr_klass' does not have access to no-arg constructor of 'initcb'
  1.3536 +    THROW_0(vmSymbols::java_lang_IllegalAccessException());
  1.3537 +  }
  1.3538 +
  1.3539 +  Handle obj = curr_klass->allocate_instance_handle(CHECK_NULL);
  1.3540 +  // Call constructor m. This might call a constructor higher up in the hierachy
  1.3541 +  JavaCalls::call_default_constructor(thread, m, obj, CHECK_NULL);
  1.3542 +
  1.3543 +  return JNIHandles::make_local(obj());
  1.3544 +JVM_END
  1.3545 +
  1.3546 +
  1.3547 +JVM_ENTRY(jobject, JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length))
  1.3548 +  JVMWrapper("JVM_AllocateNewArray");
  1.3549 +  JvmtiVMObjectAllocEventCollector oam;
  1.3550 +  oop mirror = JNIHandles::resolve_non_null(currClass);
  1.3551 +
  1.3552 +  if (java_lang_Class::is_primitive(mirror)) {
  1.3553 +    THROW_0(vmSymbols::java_lang_InvalidClassException());
  1.3554 +  }
  1.3555 +  Klass* k = java_lang_Class::as_Klass(mirror);
  1.3556 +  oop result;
  1.3557 +
  1.3558 +  if (k->oop_is_typeArray()) {
  1.3559 +    // typeArray
  1.3560 +    result = TypeArrayKlass::cast(k)->allocate(length, CHECK_NULL);
  1.3561 +  } else if (k->oop_is_objArray()) {
  1.3562 +    // objArray
  1.3563 +    ObjArrayKlass* oak = ObjArrayKlass::cast(k);
  1.3564 +    oak->initialize(CHECK_NULL); // make sure class is initialized (matches Classic VM behavior)
  1.3565 +    result = oak->allocate(length, CHECK_NULL);
  1.3566 +  } else {
  1.3567 +    THROW_0(vmSymbols::java_lang_InvalidClassException());
  1.3568 +  }
  1.3569 +  return JNIHandles::make_local(env, result);
  1.3570 +JVM_END
  1.3571 +
  1.3572 +
  1.3573 +// Return the first non-null class loader up the execution stack, or null
  1.3574 +// if only code from the null class loader is on the stack.
  1.3575 +
  1.3576 +JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
  1.3577 +  for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
  1.3578 +    // UseNewReflection
  1.3579 +    vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection
  1.3580 +    oop loader = vfst.method()->method_holder()->class_loader();
  1.3581 +    if (loader != NULL) {
  1.3582 +      return JNIHandles::make_local(env, loader);
  1.3583 +    }
  1.3584 +  }
  1.3585 +  return NULL;
  1.3586 +JVM_END
  1.3587 +
  1.3588 +
  1.3589 +// Load a class relative to the most recent class on the stack  with a non-null
  1.3590 +// classloader.
  1.3591 +// This function has been deprecated and should not be considered part of the
  1.3592 +// specified JVM interface.
  1.3593 +
  1.3594 +JVM_ENTRY(jclass, JVM_LoadClass0(JNIEnv *env, jobject receiver,
  1.3595 +                                 jclass currClass, jstring currClassName))
  1.3596 +  JVMWrapper("JVM_LoadClass0");
  1.3597 +  // Receiver is not used
  1.3598 +  ResourceMark rm(THREAD);
  1.3599 +
  1.3600 +  // Class name argument is not guaranteed to be in internal format
  1.3601 +  Handle classname (THREAD, JNIHandles::resolve_non_null(currClassName));
  1.3602 +  Handle string = java_lang_String::internalize_classname(classname, CHECK_NULL);
  1.3603 +
  1.3604 +  const char* str = java_lang_String::as_utf8_string(string());
  1.3605 +
  1.3606 +  if (str == NULL || (int)strlen(str) > Symbol::max_length()) {
  1.3607 +    // It's impossible to create this class;  the name cannot fit
  1.3608 +    // into the constant pool.
  1.3609 +    THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), str);
  1.3610 +  }
  1.3611 +
  1.3612 +  TempNewSymbol name = SymbolTable::new_symbol(str, CHECK_NULL);
  1.3613 +  Handle curr_klass (THREAD, JNIHandles::resolve(currClass));
  1.3614 +  // Find the most recent class on the stack with a non-null classloader
  1.3615 +  oop loader = NULL;
  1.3616 +  oop protection_domain = NULL;
  1.3617 +  if (curr_klass.is_null()) {
  1.3618 +    for (vframeStream vfst(thread);
  1.3619 +         !vfst.at_end() && loader == NULL;
  1.3620 +         vfst.next()) {
  1.3621 +      if (!vfst.method()->is_native()) {
  1.3622 +        InstanceKlass* holder = vfst.method()->method_holder();
  1.3623 +        loader             = holder->class_loader();
  1.3624 +        protection_domain  = holder->protection_domain();
  1.3625 +      }
  1.3626 +    }
  1.3627 +  } else {
  1.3628 +    Klass* curr_klass_oop = java_lang_Class::as_Klass(curr_klass());
  1.3629 +    loader            = InstanceKlass::cast(curr_klass_oop)->class_loader();
  1.3630 +    protection_domain = InstanceKlass::cast(curr_klass_oop)->protection_domain();
  1.3631 +  }
  1.3632 +  Handle h_loader(THREAD, loader);
  1.3633 +  Handle h_prot  (THREAD, protection_domain);
  1.3634 +  jclass result =  find_class_from_class_loader(env, name, true, h_loader, h_prot,
  1.3635 +                                                false, thread);
  1.3636 +  if (TraceClassResolution && result != NULL) {
  1.3637 +    trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
  1.3638 +  }
  1.3639 +  return result;
  1.3640 +JVM_END
  1.3641 +
  1.3642 +
  1.3643 +// Array ///////////////////////////////////////////////////////////////////////////////////////////
  1.3644 +
  1.3645 +
  1.3646 +// resolve array handle and check arguments
  1.3647 +static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) {
  1.3648 +  if (arr == NULL) {
  1.3649 +    THROW_0(vmSymbols::java_lang_NullPointerException());
  1.3650 +  }
  1.3651 +  oop a = JNIHandles::resolve_non_null(arr);
  1.3652 +  if (!a->is_array() || (type_array_only && !a->is_typeArray())) {
  1.3653 +    THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array");
  1.3654 +  }
  1.3655 +  return arrayOop(a);
  1.3656 +}
  1.3657 +
  1.3658 +
  1.3659 +JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr))
  1.3660 +  JVMWrapper("JVM_GetArrayLength");
  1.3661 +  arrayOop a = check_array(env, arr, false, CHECK_0);
  1.3662 +  return a->length();
  1.3663 +JVM_END
  1.3664 +
  1.3665 +
  1.3666 +JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index))
  1.3667 +  JVMWrapper("JVM_Array_Get");
  1.3668 +  JvmtiVMObjectAllocEventCollector oam;
  1.3669 +  arrayOop a = check_array(env, arr, false, CHECK_NULL);
  1.3670 +  jvalue value;
  1.3671 +  BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL);
  1.3672 +  oop box = Reflection::box(&value, type, CHECK_NULL);
  1.3673 +  return JNIHandles::make_local(env, box);
  1.3674 +JVM_END
  1.3675 +
  1.3676 +
  1.3677 +JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode))
  1.3678 +  JVMWrapper("JVM_GetPrimitiveArrayElement");
  1.3679 +  jvalue value;
  1.3680 +  value.i = 0; // to initialize value before getting used in CHECK
  1.3681 +  arrayOop a = check_array(env, arr, true, CHECK_(value));
  1.3682 +  assert(a->is_typeArray(), "just checking");
  1.3683 +  BasicType type = Reflection::array_get(&value, a, index, CHECK_(value));
  1.3684 +  BasicType wide_type = (BasicType) wCode;
  1.3685 +  if (type != wide_type) {
  1.3686 +    Reflection::widen(&value, type, wide_type, CHECK_(value));
  1.3687 +  }
  1.3688 +  return value;
  1.3689 +JVM_END
  1.3690 +
  1.3691 +
  1.3692 +JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val))
  1.3693 +  JVMWrapper("JVM_SetArrayElement");
  1.3694 +  arrayOop a = check_array(env, arr, false, CHECK);
  1.3695 +  oop box = JNIHandles::resolve(val);
  1.3696 +  jvalue value;
  1.3697 +  value.i = 0; // to initialize value before getting used in CHECK
  1.3698 +  BasicType value_type;
  1.3699 +  if (a->is_objArray()) {
  1.3700 +    // Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array
  1.3701 +    value_type = Reflection::unbox_for_regular_object(box, &value);
  1.3702 +  } else {
  1.3703 +    value_type = Reflection::unbox_for_primitive(box, &value, CHECK);
  1.3704 +  }
  1.3705 +  Reflection::array_set(&value, a, index, value_type, CHECK);
  1.3706 +JVM_END
  1.3707 +
  1.3708 +
  1.3709 +JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode))
  1.3710 +  JVMWrapper("JVM_SetPrimitiveArrayElement");
  1.3711 +  arrayOop a = check_array(env, arr, true, CHECK);
  1.3712 +  assert(a->is_typeArray(), "just checking");
  1.3713 +  BasicType value_type = (BasicType) vCode;
  1.3714 +  Reflection::array_set(&v, a, index, value_type, CHECK);
  1.3715 +JVM_END
  1.3716 +
  1.3717 +
  1.3718 +JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length))
  1.3719 +  JVMWrapper("JVM_NewArray");
  1.3720 +  JvmtiVMObjectAllocEventCollector oam;
  1.3721 +  oop element_mirror = JNIHandles::resolve(eltClass);
  1.3722 +  oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL);
  1.3723 +  return JNIHandles::make_local(env, result);
  1.3724 +JVM_END
  1.3725 +
  1.3726 +
  1.3727 +JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim))
  1.3728 +  JVMWrapper("JVM_NewMultiArray");
  1.3729 +  JvmtiVMObjectAllocEventCollector oam;
  1.3730 +  arrayOop dim_array = check_array(env, dim, true, CHECK_NULL);
  1.3731 +  oop element_mirror = JNIHandles::resolve(eltClass);
  1.3732 +  assert(dim_array->is_typeArray(), "just checking");
  1.3733 +  oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL);
  1.3734 +  return JNIHandles::make_local(env, result);
  1.3735 +JVM_END
  1.3736 +
  1.3737 +
  1.3738 +// Networking library support ////////////////////////////////////////////////////////////////////
  1.3739 +
  1.3740 +JVM_LEAF(jint, JVM_InitializeSocketLibrary())
  1.3741 +  JVMWrapper("JVM_InitializeSocketLibrary");
  1.3742 +  return 0;
  1.3743 +JVM_END
  1.3744 +
  1.3745 +
  1.3746 +JVM_LEAF(jint, JVM_Socket(jint domain, jint type, jint protocol))
  1.3747 +  JVMWrapper("JVM_Socket");
  1.3748 +  return os::socket(domain, type, protocol);
  1.3749 +JVM_END
  1.3750 +
  1.3751 +
  1.3752 +JVM_LEAF(jint, JVM_SocketClose(jint fd))
  1.3753 +  JVMWrapper2("JVM_SocketClose (0x%x)", fd);
  1.3754 +  //%note jvm_r6
  1.3755 +  return os::socket_close(fd);
  1.3756 +JVM_END
  1.3757 +
  1.3758 +
  1.3759 +JVM_LEAF(jint, JVM_SocketShutdown(jint fd, jint howto))
  1.3760 +  JVMWrapper2("JVM_SocketShutdown (0x%x)", fd);
  1.3761 +  //%note jvm_r6
  1.3762 +  return os::socket_shutdown(fd, howto);
  1.3763 +JVM_END
  1.3764 +
  1.3765 +
  1.3766 +JVM_LEAF(jint, JVM_Recv(jint fd, char *buf, jint nBytes, jint flags))
  1.3767 +  JVMWrapper2("JVM_Recv (0x%x)", fd);
  1.3768 +  //%note jvm_r6
  1.3769 +  return os::recv(fd, buf, (size_t)nBytes, (uint)flags);
  1.3770 +JVM_END
  1.3771 +
  1.3772 +
  1.3773 +JVM_LEAF(jint, JVM_Send(jint fd, char *buf, jint nBytes, jint flags))
  1.3774 +  JVMWrapper2("JVM_Send (0x%x)", fd);
  1.3775 +  //%note jvm_r6
  1.3776 +  return os::send(fd, buf, (size_t)nBytes, (uint)flags);
  1.3777 +JVM_END
  1.3778 +
  1.3779 +
  1.3780 +JVM_LEAF(jint, JVM_Timeout(int fd, long timeout))
  1.3781 +  JVMWrapper2("JVM_Timeout (0x%x)", fd);
  1.3782 +  //%note jvm_r6
  1.3783 +  return os::timeout(fd, timeout);
  1.3784 +JVM_END
  1.3785 +
  1.3786 +
  1.3787 +JVM_LEAF(jint, JVM_Listen(jint fd, jint count))
  1.3788 +  JVMWrapper2("JVM_Listen (0x%x)", fd);
  1.3789 +  //%note jvm_r6
  1.3790 +  return os::listen(fd, count);
  1.3791 +JVM_END
  1.3792 +
  1.3793 +
  1.3794 +JVM_LEAF(jint, JVM_Connect(jint fd, struct sockaddr *him, jint len))
  1.3795 +  JVMWrapper2("JVM_Connect (0x%x)", fd);
  1.3796 +  //%note jvm_r6
  1.3797 +  return os::connect(fd, him, (socklen_t)len);
  1.3798 +JVM_END
  1.3799 +
  1.3800 +
  1.3801 +JVM_LEAF(jint, JVM_Bind(jint fd, struct sockaddr *him, jint len))
  1.3802 +  JVMWrapper2("JVM_Bind (0x%x)", fd);
  1.3803 +  //%note jvm_r6
  1.3804 +  return os::bind(fd, him, (socklen_t)len);
  1.3805 +JVM_END
  1.3806 +
  1.3807 +
  1.3808 +JVM_LEAF(jint, JVM_Accept(jint fd, struct sockaddr *him, jint *len))
  1.3809 +  JVMWrapper2("JVM_Accept (0x%x)", fd);
  1.3810 +  //%note jvm_r6
  1.3811 +  socklen_t socklen = (socklen_t)(*len);
  1.3812 +  jint result = os::accept(fd, him, &socklen);
  1.3813 +  *len = (jint)socklen;
  1.3814 +  return result;
  1.3815 +JVM_END
  1.3816 +
  1.3817 +
  1.3818 +JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen))
  1.3819 +  JVMWrapper2("JVM_RecvFrom (0x%x)", fd);
  1.3820 +  //%note jvm_r6
  1.3821 +  socklen_t socklen = (socklen_t)(*fromlen);
  1.3822 +  jint result = os::recvfrom(fd, buf, (size_t)nBytes, (uint)flags, from, &socklen);
  1.3823 +  *fromlen = (int)socklen;
  1.3824 +  return result;
  1.3825 +JVM_END
  1.3826 +
  1.3827 +
  1.3828 +JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len))
  1.3829 +  JVMWrapper2("JVM_GetSockName (0x%x)", fd);
  1.3830 +  //%note jvm_r6
  1.3831 +  socklen_t socklen = (socklen_t)(*len);
  1.3832 +  jint result = os::get_sock_name(fd, him, &socklen);
  1.3833 +  *len = (int)socklen;
  1.3834 +  return result;
  1.3835 +JVM_END
  1.3836 +
  1.3837 +
  1.3838 +JVM_LEAF(jint, JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen))
  1.3839 +  JVMWrapper2("JVM_SendTo (0x%x)", fd);
  1.3840 +  //%note jvm_r6
  1.3841 +  return os::sendto(fd, buf, (size_t)len, (uint)flags, to, (socklen_t)tolen);
  1.3842 +JVM_END
  1.3843 +
  1.3844 +
  1.3845 +JVM_LEAF(jint, JVM_SocketAvailable(jint fd, jint *pbytes))
  1.3846 +  JVMWrapper2("JVM_SocketAvailable (0x%x)", fd);
  1.3847 +  //%note jvm_r6
  1.3848 +  return os::socket_available(fd, pbytes);
  1.3849 +JVM_END
  1.3850 +
  1.3851 +
  1.3852 +JVM_LEAF(jint, JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen))
  1.3853 +  JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
  1.3854 +  //%note jvm_r6
  1.3855 +  socklen_t socklen = (socklen_t)(*optlen);
  1.3856 +  jint result = os::get_sock_opt(fd, level, optname, optval, &socklen);
  1.3857 +  *optlen = (int)socklen;
  1.3858 +  return result;
  1.3859 +JVM_END
  1.3860 +
  1.3861 +
  1.3862 +JVM_LEAF(jint, JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen))
  1.3863 +  JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
  1.3864 +  //%note jvm_r6
  1.3865 +  return os::set_sock_opt(fd, level, optname, optval, (socklen_t)optlen);
  1.3866 +JVM_END
  1.3867 +
  1.3868 +
  1.3869 +JVM_LEAF(int, JVM_GetHostName(char* name, int namelen))
  1.3870 +  JVMWrapper("JVM_GetHostName");
  1.3871 +  return os::get_host_name(name, namelen);
  1.3872 +JVM_END
  1.3873 +
  1.3874 +
  1.3875 +// Library support ///////////////////////////////////////////////////////////////////////////
  1.3876 +
  1.3877 +JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name))
  1.3878 +  //%note jvm_ct
  1.3879 +  JVMWrapper2("JVM_LoadLibrary (%s)", name);
  1.3880 +  char ebuf[1024];
  1.3881 +  void *load_result;
  1.3882 +  {
  1.3883 +    ThreadToNativeFromVM ttnfvm(thread);
  1.3884 +    load_result = os::dll_load(name, ebuf, sizeof ebuf);
  1.3885 +  }
  1.3886 +  if (load_result == NULL) {
  1.3887 +    char msg[1024];
  1.3888 +    jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf);
  1.3889 +    // Since 'ebuf' may contain a string encoded using
  1.3890 +    // platform encoding scheme, we need to pass
  1.3891 +    // Exceptions::unsafe_to_utf8 to the new_exception method
  1.3892 +    // as the last argument. See bug 6367357.
  1.3893 +    Handle h_exception =
  1.3894 +      Exceptions::new_exception(thread,
  1.3895 +                                vmSymbols::java_lang_UnsatisfiedLinkError(),
  1.3896 +                                msg, Exceptions::unsafe_to_utf8);
  1.3897 +
  1.3898 +    THROW_HANDLE_0(h_exception);
  1.3899 +  }
  1.3900 +  return load_result;
  1.3901 +JVM_END
  1.3902 +
  1.3903 +
  1.3904 +JVM_LEAF(void, JVM_UnloadLibrary(void* handle))
  1.3905 +  JVMWrapper("JVM_UnloadLibrary");
  1.3906 +  os::dll_unload(handle);
  1.3907 +JVM_END
  1.3908 +
  1.3909 +
  1.3910 +JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
  1.3911 +  JVMWrapper2("JVM_FindLibraryEntry (%s)", name);
  1.3912 +  return os::dll_lookup(handle, name);
  1.3913 +JVM_END
  1.3914 +
  1.3915 +
  1.3916 +// Floating point support ////////////////////////////////////////////////////////////////////
  1.3917 +
  1.3918 +JVM_LEAF(jboolean, JVM_IsNaN(jdouble a))
  1.3919 +  JVMWrapper("JVM_IsNaN");
  1.3920 +  return g_isnan(a);
  1.3921 +JVM_END
  1.3922 +
  1.3923 +
  1.3924 +// JNI version ///////////////////////////////////////////////////////////////////////////////
  1.3925 +
  1.3926 +JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
  1.3927 +  JVMWrapper2("JVM_IsSupportedJNIVersion (%d)", version);
  1.3928 +  return Threads::is_supported_jni_version_including_1_1(version);
  1.3929 +JVM_END
  1.3930 +
  1.3931 +
  1.3932 +// String support ///////////////////////////////////////////////////////////////////////////
  1.3933 +
  1.3934 +JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
  1.3935 +  JVMWrapper("JVM_InternString");
  1.3936 +  JvmtiVMObjectAllocEventCollector oam;
  1.3937 +  if (str == NULL) return NULL;
  1.3938 +  oop string = JNIHandles::resolve_non_null(str);
  1.3939 +  oop result = StringTable::intern(string, CHECK_NULL);
  1.3940 +  return (jstring) JNIHandles::make_local(env, result);
  1.3941 +JVM_END
  1.3942 +
  1.3943 +
  1.3944 +// Raw monitor support //////////////////////////////////////////////////////////////////////
  1.3945 +
  1.3946 +// The lock routine below calls lock_without_safepoint_check in order to get a raw lock
  1.3947 +// without interfering with the safepoint mechanism. The routines are not JVM_LEAF because
  1.3948 +// they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check
  1.3949 +// that only works with java threads.
  1.3950 +
  1.3951 +
  1.3952 +JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
  1.3953 +  VM_Exit::block_if_vm_exited();
  1.3954 +  JVMWrapper("JVM_RawMonitorCreate");
  1.3955 +  return new Mutex(Mutex::native, "JVM_RawMonitorCreate");
  1.3956 +}
  1.3957 +
  1.3958 +
  1.3959 +JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
  1.3960 +  VM_Exit::block_if_vm_exited();
  1.3961 +  JVMWrapper("JVM_RawMonitorDestroy");
  1.3962 +  delete ((Mutex*) mon);
  1.3963 +}
  1.3964 +
  1.3965 +
  1.3966 +JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
  1.3967 +  VM_Exit::block_if_vm_exited();
  1.3968 +  JVMWrapper("JVM_RawMonitorEnter");
  1.3969 +  ((Mutex*) mon)->jvm_raw_lock();
  1.3970 +  return 0;
  1.3971 +}
  1.3972 +
  1.3973 +
  1.3974 +JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
  1.3975 +  VM_Exit::block_if_vm_exited();
  1.3976 +  JVMWrapper("JVM_RawMonitorExit");
  1.3977 +  ((Mutex*) mon)->jvm_raw_unlock();
  1.3978 +}
  1.3979 +
  1.3980 +
  1.3981 +// Support for Serialization
  1.3982 +
  1.3983 +typedef jfloat  (JNICALL *IntBitsToFloatFn  )(JNIEnv* env, jclass cb, jint    value);
  1.3984 +typedef jdouble (JNICALL *LongBitsToDoubleFn)(JNIEnv* env, jclass cb, jlong   value);
  1.3985 +typedef jint    (JNICALL *FloatToIntBitsFn  )(JNIEnv* env, jclass cb, jfloat  value);
  1.3986 +typedef jlong   (JNICALL *DoubleToLongBitsFn)(JNIEnv* env, jclass cb, jdouble value);
  1.3987 +
  1.3988 +static IntBitsToFloatFn   int_bits_to_float_fn   = NULL;
  1.3989 +static LongBitsToDoubleFn long_bits_to_double_fn = NULL;
  1.3990 +static FloatToIntBitsFn   float_to_int_bits_fn   = NULL;
  1.3991 +static DoubleToLongBitsFn double_to_long_bits_fn = NULL;
  1.3992 +
  1.3993 +
  1.3994 +void initialize_converter_functions() {
  1.3995 +  if (JDK_Version::is_gte_jdk14x_version()) {
  1.3996 +    // These functions only exist for compatibility with 1.3.1 and earlier
  1.3997 +    return;
  1.3998 +  }
  1.3999 +
  1.4000 +  // called from universe_post_init()
  1.4001 +  assert(
  1.4002 +    int_bits_to_float_fn   == NULL &&
  1.4003 +    long_bits_to_double_fn == NULL &&
  1.4004 +    float_to_int_bits_fn   == NULL &&
  1.4005 +    double_to_long_bits_fn == NULL ,
  1.4006 +    "initialization done twice"
  1.4007 +  );
  1.4008 +  // initialize
  1.4009 +  int_bits_to_float_fn   = CAST_TO_FN_PTR(IntBitsToFloatFn  , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat"  , "(I)F"));
  1.4010 +  long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D"));
  1.4011 +  float_to_int_bits_fn   = CAST_TO_FN_PTR(FloatToIntBitsFn  , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits"  , "(F)I"));
  1.4012 +  double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J"));
  1.4013 +  // verify
  1.4014 +  assert(
  1.4015 +    int_bits_to_float_fn   != NULL &&
  1.4016 +    long_bits_to_double_fn != NULL &&
  1.4017 +    float_to_int_bits_fn   != NULL &&
  1.4018 +    double_to_long_bits_fn != NULL ,
  1.4019 +    "initialization failed"
  1.4020 +  );
  1.4021 +}
  1.4022 +
  1.4023 +
  1.4024 +
  1.4025 +// Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
  1.4026 +
  1.4027 +jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
  1.4028 +                                    Handle loader, Handle protection_domain,
  1.4029 +                                    jboolean throwError, TRAPS) {
  1.4030 +  // Security Note:
  1.4031 +  //   The Java level wrapper will perform the necessary security check allowing
  1.4032 +  //   us to pass the NULL as the initiating class loader.  The VM is responsible for
  1.4033 +  //   the checkPackageAccess relative to the initiating class loader via the
  1.4034 +  //   protection_domain. The protection_domain is passed as NULL by the java code
  1.4035 +  //   if there is no security manager in 3-arg Class.forName().
  1.4036 +  Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
  1.4037 +
  1.4038 +  KlassHandle klass_handle(THREAD, klass);
  1.4039 +  // Check if we should initialize the class
  1.4040 +  if (init && klass_handle->oop_is_instance()) {
  1.4041 +    klass_handle->initialize(CHECK_NULL);
  1.4042 +  }
  1.4043 +  return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror());
  1.4044 +}
  1.4045 +
  1.4046 +
  1.4047 +// Internal SQE debugging support ///////////////////////////////////////////////////////////
  1.4048 +
  1.4049 +#ifndef PRODUCT
  1.4050 +
  1.4051 +extern "C" {
  1.4052 +  JNIEXPORT jboolean JNICALL JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get);
  1.4053 +  JNIEXPORT jboolean JNICALL JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get);
  1.4054 +  JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj);
  1.4055 +}
  1.4056 +
  1.4057 +JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get))
  1.4058 +  JVMWrapper("JVM_AccessBoolVMFlag");
  1.4059 +  return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, Flag::INTERNAL);
  1.4060 +JVM_END
  1.4061 +
  1.4062 +JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get))
  1.4063 +  JVMWrapper("JVM_AccessVMIntFlag");
  1.4064 +  intx v;
  1.4065 +  jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, Flag::INTERNAL);
  1.4066 +  *value = (jint)v;
  1.4067 +  return result;
  1.4068 +JVM_END
  1.4069 +
  1.4070 +
  1.4071 +JVM_ENTRY(void, JVM_VMBreakPoint(JNIEnv *env, jobject obj))
  1.4072 +  JVMWrapper("JVM_VMBreakPoint");
  1.4073 +  oop the_obj = JNIHandles::resolve(obj);
  1.4074 +  BREAKPOINT;
  1.4075 +JVM_END
  1.4076 +
  1.4077 +
  1.4078 +#endif
  1.4079 +
  1.4080 +
  1.4081 +// Method ///////////////////////////////////////////////////////////////////////////////////////////
  1.4082 +
  1.4083 +JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
  1.4084 +  JVMWrapper("JVM_InvokeMethod");
  1.4085 +  Handle method_handle;
  1.4086 +  if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
  1.4087 +    method_handle = Handle(THREAD, JNIHandles::resolve(method));
  1.4088 +    Handle receiver(THREAD, JNIHandles::resolve(obj));
  1.4089 +    objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
  1.4090 +    oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
  1.4091 +    jobject res = JNIHandles::make_local(env, result);
  1.4092 +    if (JvmtiExport::should_post_vm_object_alloc()) {
  1.4093 +      oop ret_type = java_lang_reflect_Method::return_type(method_handle());
  1.4094 +      assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
  1.4095 +      if (java_lang_Class::is_primitive(ret_type)) {
  1.4096 +        // Only for primitive type vm allocates memory for java object.
  1.4097 +        // See box() method.
  1.4098 +        JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
  1.4099 +      }
  1.4100 +    }
  1.4101 +    return res;
  1.4102 +  } else {
  1.4103 +    THROW_0(vmSymbols::java_lang_StackOverflowError());
  1.4104 +  }
  1.4105 +JVM_END
  1.4106 +
  1.4107 +
  1.4108 +JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
  1.4109 +  JVMWrapper("JVM_NewInstanceFromConstructor");
  1.4110 +  oop constructor_mirror = JNIHandles::resolve(c);
  1.4111 +  objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
  1.4112 +  oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
  1.4113 +  jobject res = JNIHandles::make_local(env, result);
  1.4114 +  if (JvmtiExport::should_post_vm_object_alloc()) {
  1.4115 +    JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
  1.4116 +  }
  1.4117 +  return res;
  1.4118 +JVM_END
  1.4119 +
  1.4120 +// Atomic ///////////////////////////////////////////////////////////////////////////////////////////
  1.4121 +
  1.4122 +JVM_LEAF(jboolean, JVM_SupportsCX8())
  1.4123 +  JVMWrapper("JVM_SupportsCX8");
  1.4124 +  return VM_Version::supports_cx8();
  1.4125 +JVM_END
  1.4126 +
  1.4127 +
  1.4128 +JVM_ENTRY(jboolean, JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal))
  1.4129 +  JVMWrapper("JVM_CX8Field");
  1.4130 +  jlong res;
  1.4131 +  oop             o       = JNIHandles::resolve(obj);
  1.4132 +  intptr_t        fldOffs = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
  1.4133 +  volatile jlong* addr    = (volatile jlong*)((address)o + fldOffs);
  1.4134 +
  1.4135 +  assert(VM_Version::supports_cx8(), "cx8 not supported");
  1.4136 +  res = Atomic::cmpxchg(newVal, addr, oldVal);
  1.4137 +
  1.4138 +  return res == oldVal;
  1.4139 +JVM_END
  1.4140 +
  1.4141 +// DTrace ///////////////////////////////////////////////////////////////////
  1.4142 +
  1.4143 +JVM_ENTRY(jint, JVM_DTraceGetVersion(JNIEnv* env))
  1.4144 +  JVMWrapper("JVM_DTraceGetVersion");
  1.4145 +  return (jint)JVM_TRACING_DTRACE_VERSION;
  1.4146 +JVM_END
  1.4147 +
  1.4148 +JVM_ENTRY(jlong,JVM_DTraceActivate(
  1.4149 +    JNIEnv* env, jint version, jstring module_name, jint providers_count,
  1.4150 +    JVM_DTraceProvider* providers))
  1.4151 +  JVMWrapper("JVM_DTraceActivate");
  1.4152 +  return DTraceJSDT::activate(
  1.4153 +    version, module_name, providers_count, providers, CHECK_0);
  1.4154 +JVM_END
  1.4155 +
  1.4156 +JVM_ENTRY(jboolean,JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method))
  1.4157 +  JVMWrapper("JVM_DTraceIsProbeEnabled");
  1.4158 +  return DTraceJSDT::is_probe_enabled(method);
  1.4159 +JVM_END
  1.4160 +
  1.4161 +JVM_ENTRY(void,JVM_DTraceDispose(JNIEnv* env, jlong handle))
  1.4162 +  JVMWrapper("JVM_DTraceDispose");
  1.4163 +  DTraceJSDT::dispose(handle);
  1.4164 +JVM_END
  1.4165 +
  1.4166 +JVM_ENTRY(jboolean,JVM_DTraceIsSupported(JNIEnv* env))
  1.4167 +  JVMWrapper("JVM_DTraceIsSupported");
  1.4168 +  return DTraceJSDT::is_supported();
  1.4169 +JVM_END
  1.4170 +
  1.4171 +// Returns an array of all live Thread objects (VM internal JavaThreads,
  1.4172 +// jvmti agent threads, and JNI attaching threads  are skipped)
  1.4173 +// See CR 6404306 regarding JNI attaching threads
  1.4174 +JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy))
  1.4175 +  ResourceMark rm(THREAD);
  1.4176 +  ThreadsListEnumerator tle(THREAD, false, false);
  1.4177 +  JvmtiVMObjectAllocEventCollector oam;
  1.4178 +
  1.4179 +  int num_threads = tle.num_threads();
  1.4180 +  objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL);
  1.4181 +  objArrayHandle threads_ah(THREAD, r);
  1.4182 +
  1.4183 +  for (int i = 0; i < num_threads; i++) {
  1.4184 +    Handle h = tle.get_threadObj(i);
  1.4185 +    threads_ah->obj_at_put(i, h());
  1.4186 +  }
  1.4187 +
  1.4188 +  return (jobjectArray) JNIHandles::make_local(env, threads_ah());
  1.4189 +JVM_END
  1.4190 +
  1.4191 +
  1.4192 +// Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
  1.4193 +// Return StackTraceElement[][], each element is the stack trace of a thread in
  1.4194 +// the corresponding entry in the given threads array
  1.4195 +JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
  1.4196 +  JVMWrapper("JVM_DumpThreads");
  1.4197 +  JvmtiVMObjectAllocEventCollector oam;
  1.4198 +
  1.4199 +  // Check if threads is null
  1.4200 +  if (threads == NULL) {
  1.4201 +    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
  1.4202 +  }
  1.4203 +
  1.4204 +  objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
  1.4205 +  objArrayHandle ah(THREAD, a);
  1.4206 +  int num_threads = ah->length();
  1.4207 +  // check if threads is non-empty array
  1.4208 +  if (num_threads == 0) {
  1.4209 +    THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
  1.4210 +  }
  1.4211 +
  1.4212 +  // check if threads is not an array of objects of Thread class
  1.4213 +  Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
  1.4214 +  if (k != SystemDictionary::Thread_klass()) {
  1.4215 +    THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
  1.4216 +  }
  1.4217 +
  1.4218 +  ResourceMark rm(THREAD);
  1.4219 +
  1.4220 +  GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
  1.4221 +  for (int i = 0; i < num_threads; i++) {
  1.4222 +    oop thread_obj = ah->obj_at(i);
  1.4223 +    instanceHandle h(THREAD, (instanceOop) thread_obj);
  1.4224 +    thread_handle_array->append(h);
  1.4225 +  }
  1.4226 +
  1.4227 +  Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
  1.4228 +  return (jobjectArray)JNIHandles::make_local(env, stacktraces());
  1.4229 +
  1.4230 +JVM_END
  1.4231 +
  1.4232 +// JVM monitoring and management support
  1.4233 +JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version))
  1.4234 +  return Management::get_jmm_interface(version);
  1.4235 +JVM_END
  1.4236 +
  1.4237 +// com.sun.tools.attach.VirtualMachine agent properties support
  1.4238 +//
  1.4239 +// Initialize the agent properties with the properties maintained in the VM
  1.4240 +JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
  1.4241 +  JVMWrapper("JVM_InitAgentProperties");
  1.4242 +  ResourceMark rm;
  1.4243 +
  1.4244 +  Handle props(THREAD, JNIHandles::resolve_non_null(properties));
  1.4245 +
  1.4246 +  PUTPROP(props, "sun.java.command", Arguments::java_command());
  1.4247 +  PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags());
  1.4248 +  PUTPROP(props, "sun.jvm.args", Arguments::jvm_args());
  1.4249 +  return properties;
  1.4250 +JVM_END
  1.4251 +
  1.4252 +JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass))
  1.4253 +{
  1.4254 +  JVMWrapper("JVM_GetEnclosingMethodInfo");
  1.4255 +  JvmtiVMObjectAllocEventCollector oam;
  1.4256 +
  1.4257 +  if (ofClass == NULL) {
  1.4258 +    return NULL;
  1.4259 +  }
  1.4260 +  Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass));
  1.4261 +  // Special handling for primitive objects
  1.4262 +  if (java_lang_Class::is_primitive(mirror())) {
  1.4263 +    return NULL;
  1.4264 +  }
  1.4265 +  Klass* k = java_lang_Class::as_Klass(mirror());
  1.4266 +  if (!k->oop_is_instance()) {
  1.4267 +    return NULL;
  1.4268 +  }
  1.4269 +  instanceKlassHandle ik_h(THREAD, k);
  1.4270 +  int encl_method_class_idx = ik_h->enclosing_method_class_index();
  1.4271 +  if (encl_method_class_idx == 0) {
  1.4272 +    return NULL;
  1.4273 +  }
  1.4274 +  objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL);
  1.4275 +  objArrayHandle dest(THREAD, dest_o);
  1.4276 +  Klass* enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
  1.4277 +  dest->obj_at_put(0, enc_k->java_mirror());
  1.4278 +  int encl_method_method_idx = ik_h->enclosing_method_method_index();
  1.4279 +  if (encl_method_method_idx != 0) {
  1.4280 +    Symbol* sym = ik_h->constants()->symbol_at(
  1.4281 +                        extract_low_short_from_int(
  1.4282 +                          ik_h->constants()->name_and_type_at(encl_method_method_idx)));
  1.4283 +    Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
  1.4284 +    dest->obj_at_put(1, str());
  1.4285 +    sym = ik_h->constants()->symbol_at(
  1.4286 +              extract_high_short_from_int(
  1.4287 +                ik_h->constants()->name_and_type_at(encl_method_method_idx)));
  1.4288 +    str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
  1.4289 +    dest->obj_at_put(2, str());
  1.4290 +  }
  1.4291 +  return (jobjectArray) JNIHandles::make_local(dest());
  1.4292 +}
  1.4293 +JVM_END
  1.4294 +
  1.4295 +JVM_ENTRY(jintArray, JVM_GetThreadStateValues(JNIEnv* env,
  1.4296 +                                              jint javaThreadState))
  1.4297 +{
  1.4298 +  // If new thread states are added in future JDK and VM versions,
  1.4299 +  // this should check if the JDK version is compatible with thread
  1.4300 +  // states supported by the VM.  Return NULL if not compatible.
  1.4301 +  //
  1.4302 +  // This function must map the VM java_lang_Thread::ThreadStatus
  1.4303 +  // to the Java thread state that the JDK supports.
  1.4304 +  //
  1.4305 +
  1.4306 +  typeArrayHandle values_h;
  1.4307 +  switch (javaThreadState) {
  1.4308 +    case JAVA_THREAD_STATE_NEW : {
  1.4309 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
  1.4310 +      values_h = typeArrayHandle(THREAD, r);
  1.4311 +      values_h->int_at_put(0, java_lang_Thread::NEW);
  1.4312 +      break;
  1.4313 +    }
  1.4314 +    case JAVA_THREAD_STATE_RUNNABLE : {
  1.4315 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
  1.4316 +      values_h = typeArrayHandle(THREAD, r);
  1.4317 +      values_h->int_at_put(0, java_lang_Thread::RUNNABLE);
  1.4318 +      break;
  1.4319 +    }
  1.4320 +    case JAVA_THREAD_STATE_BLOCKED : {
  1.4321 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
  1.4322 +      values_h = typeArrayHandle(THREAD, r);
  1.4323 +      values_h->int_at_put(0, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
  1.4324 +      break;
  1.4325 +    }
  1.4326 +    case JAVA_THREAD_STATE_WAITING : {
  1.4327 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL);
  1.4328 +      values_h = typeArrayHandle(THREAD, r);
  1.4329 +      values_h->int_at_put(0, java_lang_Thread::IN_OBJECT_WAIT);
  1.4330 +      values_h->int_at_put(1, java_lang_Thread::PARKED);
  1.4331 +      break;
  1.4332 +    }
  1.4333 +    case JAVA_THREAD_STATE_TIMED_WAITING : {
  1.4334 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 3, CHECK_NULL);
  1.4335 +      values_h = typeArrayHandle(THREAD, r);
  1.4336 +      values_h->int_at_put(0, java_lang_Thread::SLEEPING);
  1.4337 +      values_h->int_at_put(1, java_lang_Thread::IN_OBJECT_WAIT_TIMED);
  1.4338 +      values_h->int_at_put(2, java_lang_Thread::PARKED_TIMED);
  1.4339 +      break;
  1.4340 +    }
  1.4341 +    case JAVA_THREAD_STATE_TERMINATED : {
  1.4342 +      typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
  1.4343 +      values_h = typeArrayHandle(THREAD, r);
  1.4344 +      values_h->int_at_put(0, java_lang_Thread::TERMINATED);
  1.4345 +      break;
  1.4346 +    }
  1.4347 +    default:
  1.4348 +      // Unknown state - probably incompatible JDK version
  1.4349 +      return NULL;
  1.4350 +  }
  1.4351 +
  1.4352 +  return (jintArray) JNIHandles::make_local(env, values_h());
  1.4353 +}
  1.4354 +JVM_END
  1.4355 +
  1.4356 +
  1.4357 +JVM_ENTRY(jobjectArray, JVM_GetThreadStateNames(JNIEnv* env,
  1.4358 +                                                jint javaThreadState,
  1.4359 +                                                jintArray values))
  1.4360 +{
  1.4361 +  // If new thread states are added in future JDK and VM versions,
  1.4362 +  // this should check if the JDK version is compatible with thread
  1.4363 +  // states supported by the VM.  Return NULL if not compatible.
  1.4364 +  //
  1.4365 +  // This function must map the VM java_lang_Thread::ThreadStatus
  1.4366 +  // to the Java thread state that the JDK supports.
  1.4367 +  //
  1.4368 +
  1.4369 +  ResourceMark rm;
  1.4370 +
  1.4371 +  // Check if threads is null
  1.4372 +  if (values == NULL) {
  1.4373 +    THROW_(vmSymbols::java_lang_NullPointerException(), 0);
  1.4374 +  }
  1.4375 +
  1.4376 +  typeArrayOop v = typeArrayOop(JNIHandles::resolve_non_null(values));
  1.4377 +  typeArrayHandle values_h(THREAD, v);
  1.4378 +
  1.4379 +  objArrayHandle names_h;
  1.4380 +  switch (javaThreadState) {
  1.4381 +    case JAVA_THREAD_STATE_NEW : {
  1.4382 +      assert(values_h->length() == 1 &&
  1.4383 +               values_h->int_at(0) == java_lang_Thread::NEW,
  1.4384 +             "Invalid threadStatus value");
  1.4385 +
  1.4386 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4387 +                                               1, /* only 1 substate */
  1.4388 +                                               CHECK_NULL);
  1.4389 +      names_h = objArrayHandle(THREAD, r);
  1.4390 +      Handle name = java_lang_String::create_from_str("NEW", CHECK_NULL);
  1.4391 +      names_h->obj_at_put(0, name());
  1.4392 +      break;
  1.4393 +    }
  1.4394 +    case JAVA_THREAD_STATE_RUNNABLE : {
  1.4395 +      assert(values_h->length() == 1 &&
  1.4396 +               values_h->int_at(0) == java_lang_Thread::RUNNABLE,
  1.4397 +             "Invalid threadStatus value");
  1.4398 +
  1.4399 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4400 +                                               1, /* only 1 substate */
  1.4401 +                                               CHECK_NULL);
  1.4402 +      names_h = objArrayHandle(THREAD, r);
  1.4403 +      Handle name = java_lang_String::create_from_str("RUNNABLE", CHECK_NULL);
  1.4404 +      names_h->obj_at_put(0, name());
  1.4405 +      break;
  1.4406 +    }
  1.4407 +    case JAVA_THREAD_STATE_BLOCKED : {
  1.4408 +      assert(values_h->length() == 1 &&
  1.4409 +               values_h->int_at(0) == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER,
  1.4410 +             "Invalid threadStatus value");
  1.4411 +
  1.4412 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4413 +                                               1, /* only 1 substate */
  1.4414 +                                               CHECK_NULL);
  1.4415 +      names_h = objArrayHandle(THREAD, r);
  1.4416 +      Handle name = java_lang_String::create_from_str("BLOCKED", CHECK_NULL);
  1.4417 +      names_h->obj_at_put(0, name());
  1.4418 +      break;
  1.4419 +    }
  1.4420 +    case JAVA_THREAD_STATE_WAITING : {
  1.4421 +      assert(values_h->length() == 2 &&
  1.4422 +               values_h->int_at(0) == java_lang_Thread::IN_OBJECT_WAIT &&
  1.4423 +               values_h->int_at(1) == java_lang_Thread::PARKED,
  1.4424 +             "Invalid threadStatus value");
  1.4425 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4426 +                                               2, /* number of substates */
  1.4427 +                                               CHECK_NULL);
  1.4428 +      names_h = objArrayHandle(THREAD, r);
  1.4429 +      Handle name0 = java_lang_String::create_from_str("WAITING.OBJECT_WAIT",
  1.4430 +                                                       CHECK_NULL);
  1.4431 +      Handle name1 = java_lang_String::create_from_str("WAITING.PARKED",
  1.4432 +                                                       CHECK_NULL);
  1.4433 +      names_h->obj_at_put(0, name0());
  1.4434 +      names_h->obj_at_put(1, name1());
  1.4435 +      break;
  1.4436 +    }
  1.4437 +    case JAVA_THREAD_STATE_TIMED_WAITING : {
  1.4438 +      assert(values_h->length() == 3 &&
  1.4439 +               values_h->int_at(0) == java_lang_Thread::SLEEPING &&
  1.4440 +               values_h->int_at(1) == java_lang_Thread::IN_OBJECT_WAIT_TIMED &&
  1.4441 +               values_h->int_at(2) == java_lang_Thread::PARKED_TIMED,
  1.4442 +             "Invalid threadStatus value");
  1.4443 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4444 +                                               3, /* number of substates */
  1.4445 +                                               CHECK_NULL);
  1.4446 +      names_h = objArrayHandle(THREAD, r);
  1.4447 +      Handle name0 = java_lang_String::create_from_str("TIMED_WAITING.SLEEPING",
  1.4448 +                                                       CHECK_NULL);
  1.4449 +      Handle name1 = java_lang_String::create_from_str("TIMED_WAITING.OBJECT_WAIT",
  1.4450 +                                                       CHECK_NULL);
  1.4451 +      Handle name2 = java_lang_String::create_from_str("TIMED_WAITING.PARKED",
  1.4452 +                                                       CHECK_NULL);
  1.4453 +      names_h->obj_at_put(0, name0());
  1.4454 +      names_h->obj_at_put(1, name1());
  1.4455 +      names_h->obj_at_put(2, name2());
  1.4456 +      break;
  1.4457 +    }
  1.4458 +    case JAVA_THREAD_STATE_TERMINATED : {
  1.4459 +      assert(values_h->length() == 1 &&
  1.4460 +               values_h->int_at(0) == java_lang_Thread::TERMINATED,
  1.4461 +             "Invalid threadStatus value");
  1.4462 +      objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
  1.4463 +                                               1, /* only 1 substate */
  1.4464 +                                               CHECK_NULL);
  1.4465 +      names_h = objArrayHandle(THREAD, r);
  1.4466 +      Handle name = java_lang_String::create_from_str("TERMINATED", CHECK_NULL);
  1.4467 +      names_h->obj_at_put(0, name());
  1.4468 +      break;
  1.4469 +    }
  1.4470 +    default:
  1.4471 +      // Unknown state - probably incompatible JDK version
  1.4472 +      return NULL;
  1.4473 +  }
  1.4474 +  return (jobjectArray) JNIHandles::make_local(env, names_h());
  1.4475 +}
  1.4476 +JVM_END
  1.4477 +
  1.4478 +JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size))
  1.4479 +{
  1.4480 +  memset(info, 0, sizeof(info_size));
  1.4481 +
  1.4482 +  info->jvm_version = Abstract_VM_Version::jvm_version();
  1.4483 +  info->update_version = 0;          /* 0 in HotSpot Express VM */
  1.4484 +  info->special_update_version = 0;  /* 0 in HotSpot Express VM */
  1.4485 +
  1.4486 +  // when we add a new capability in the jvm_version_info struct, we should also
  1.4487 +  // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat
  1.4488 +  // counter defined in runtimeService.cpp.
  1.4489 +  info->is_attachable = AttachListener::is_attach_supported();
  1.4490 +}
  1.4491 +JVM_END

mercurial