src/share/vm/prims/jvm.cpp

Fri, 23 Sep 2016 23:07:57 -0700

author
asaha
date
Fri, 23 Sep 2016 23:07:57 -0700
changeset 8628
fa9ea9d2801f
parent 8609
db2cffccdb85
parent 8586
1ccd27199595
child 8716
619700f41f8e
permissions
-rw-r--r--

Merge

duke@435 1 /*
shshahma@8584 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/classLoader.hpp"
iklam@7322 27 #include "classfile/classLoaderExt.hpp"
stefank@2314 28 #include "classfile/javaAssertions.hpp"
stefank@2314 29 #include "classfile/javaClasses.hpp"
stefank@2314 30 #include "classfile/symbolTable.hpp"
stefank@2314 31 #include "classfile/systemDictionary.hpp"
iklam@7089 32 #if INCLUDE_CDS
iklam@7089 33 #include "classfile/sharedClassUtil.hpp"
iklam@7089 34 #include "classfile/systemDictionaryShared.hpp"
iklam@7089 35 #endif
stefank@2314 36 #include "classfile/vmSymbols.hpp"
stefank@2314 37 #include "gc_interface/collectedHeap.inline.hpp"
twisti@4866 38 #include "interpreter/bytecode.hpp"
stefank@2314 39 #include "memory/oopFactory.hpp"
stefank@2314 40 #include "memory/universe.inline.hpp"
never@3137 41 #include "oops/fieldStreams.hpp"
stefank@2314 42 #include "oops/instanceKlass.hpp"
stefank@2314 43 #include "oops/objArrayKlass.hpp"
coleenp@4037 44 #include "oops/method.hpp"
stefank@2314 45 #include "prims/jvm.h"
stefank@2314 46 #include "prims/jvm_misc.hpp"
stefank@2314 47 #include "prims/jvmtiExport.hpp"
stefank@2314 48 #include "prims/jvmtiThreadState.hpp"
stefank@2314 49 #include "prims/nativeLookup.hpp"
stefank@2314 50 #include "prims/privilegedStack.hpp"
stefank@2314 51 #include "runtime/arguments.hpp"
stefank@2314 52 #include "runtime/dtraceJSDT.hpp"
stefank@2314 53 #include "runtime/handles.inline.hpp"
stefank@2314 54 #include "runtime/init.hpp"
stefank@2314 55 #include "runtime/interfaceSupport.hpp"
stefank@2314 56 #include "runtime/java.hpp"
stefank@2314 57 #include "runtime/javaCalls.hpp"
stefank@2314 58 #include "runtime/jfieldIDWorkaround.hpp"
goetz@6911 59 #include "runtime/orderAccess.inline.hpp"
stefank@2314 60 #include "runtime/os.hpp"
stefank@2314 61 #include "runtime/perfData.hpp"
stefank@2314 62 #include "runtime/reflection.hpp"
stefank@2314 63 #include "runtime/vframe.hpp"
stefank@2314 64 #include "runtime/vm_operations.hpp"
stefank@2314 65 #include "services/attachListener.hpp"
stefank@2314 66 #include "services/management.hpp"
stefank@2314 67 #include "services/threadService.hpp"
sla@5237 68 #include "trace/tracing.hpp"
stefank@2314 69 #include "utilities/copy.hpp"
stefank@2314 70 #include "utilities/defaultStream.hpp"
stefank@2314 71 #include "utilities/dtrace.hpp"
stefank@2314 72 #include "utilities/events.hpp"
stefank@2314 73 #include "utilities/histogram.hpp"
stefank@2314 74 #include "utilities/top.hpp"
stefank@2314 75 #include "utilities/utf8.hpp"
stefank@2314 76 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 77 # include "jvm_linux.h"
stefank@2314 78 #endif
stefank@2314 79 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 80 # include "jvm_solaris.h"
stefank@2314 81 #endif
stefank@2314 82 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 83 # include "jvm_windows.h"
stefank@2314 84 #endif
goetz@6461 85 #ifdef TARGET_OS_FAMILY_aix
goetz@6461 86 # include "jvm_aix.h"
goetz@6461 87 #endif
never@3156 88 #ifdef TARGET_OS_FAMILY_bsd
never@3156 89 # include "jvm_bsd.h"
never@3156 90 #endif
stefank@2314 91
duke@435 92 #include <errno.h>
duke@435 93
dcubed@3202 94 #ifndef USDT2
fparain@1759 95 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
fparain@1759 96 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
fparain@1759 97 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
dcubed@3202 98 #endif /* !USDT2 */
fparain@1759 99
duke@435 100 /*
duke@435 101 NOTE about use of any ctor or function call that can trigger a safepoint/GC:
duke@435 102 such ctors and calls MUST NOT come between an oop declaration/init and its
duke@435 103 usage because if objects are move this may cause various memory stomps, bus
duke@435 104 errors and segfaults. Here is a cookbook for causing so called "naked oop
duke@435 105 failures":
duke@435 106
duke@435 107 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
duke@435 108 JVMWrapper("JVM_GetClassDeclaredFields");
duke@435 109
duke@435 110 // Object address to be held directly in mirror & not visible to GC
duke@435 111 oop mirror = JNIHandles::resolve_non_null(ofClass);
duke@435 112
duke@435 113 // If this ctor can hit a safepoint, moving objects around, then
duke@435 114 ComplexConstructor foo;
duke@435 115
duke@435 116 // Boom! mirror may point to JUNK instead of the intended object
duke@435 117 (some dereference of mirror)
duke@435 118
duke@435 119 // Here's another call that may block for GC, making mirror stale
duke@435 120 MutexLocker ml(some_lock);
duke@435 121
duke@435 122 // And here's an initializer that can result in a stale oop
duke@435 123 // all in one step.
duke@435 124 oop o = call_that_can_throw_exception(TRAPS);
duke@435 125
duke@435 126
duke@435 127 The solution is to keep the oop declaration BELOW the ctor or function
duke@435 128 call that might cause a GC, do another resolve to reassign the oop, or
duke@435 129 consider use of a Handle instead of an oop so there is immunity from object
duke@435 130 motion. But note that the "QUICK" entries below do not have a handlemark
duke@435 131 and thus can only support use of handles passed in.
duke@435 132 */
duke@435 133
coleenp@4037 134 static void trace_class_resolution_impl(Klass* to_class, TRAPS) {
duke@435 135 ResourceMark rm;
duke@435 136 int line_number = -1;
duke@435 137 const char * source_file = NULL;
acorn@1092 138 const char * trace = "explicit";
coleenp@4251 139 InstanceKlass* caller = NULL;
duke@435 140 JavaThread* jthread = JavaThread::current();
duke@435 141 if (jthread->has_last_Java_frame()) {
duke@435 142 vframeStream vfst(jthread);
duke@435 143
duke@435 144 // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames
coleenp@2497 145 TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController", CHECK);
coleenp@4037 146 Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK);
coleenp@2497 147 TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction", CHECK);
coleenp@4037 148 Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK);
coleenp@4037 149
coleenp@4037 150 Method* last_caller = NULL;
duke@435 151
duke@435 152 while (!vfst.at_end()) {
coleenp@4037 153 Method* m = vfst.method();
coleenp@4037 154 if (!vfst.method()->method_holder()->is_subclass_of(SystemDictionary::ClassLoader_klass())&&
coleenp@4037 155 !vfst.method()->method_holder()->is_subclass_of(access_controller_klass) &&
coleenp@4037 156 !vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) {
duke@435 157 break;
duke@435 158 }
duke@435 159 last_caller = m;
duke@435 160 vfst.next();
duke@435 161 }
duke@435 162 // if this is called from Class.forName0 and that is called from Class.forName,
duke@435 163 // then print the caller of Class.forName. If this is Class.loadClass, then print
duke@435 164 // that caller, otherwise keep quiet since this should be picked up elsewhere.
duke@435 165 bool found_it = false;
duke@435 166 if (!vfst.at_end() &&
coleenp@4251 167 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
duke@435 168 vfst.method()->name() == vmSymbols::forName0_name()) {
duke@435 169 vfst.next();
duke@435 170 if (!vfst.at_end() &&
coleenp@4251 171 vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
duke@435 172 vfst.method()->name() == vmSymbols::forName_name()) {
duke@435 173 vfst.next();
duke@435 174 found_it = true;
duke@435 175 }
duke@435 176 } else if (last_caller != NULL &&
coleenp@4251 177 last_caller->method_holder()->name() ==
duke@435 178 vmSymbols::java_lang_ClassLoader() &&
duke@435 179 (last_caller->name() == vmSymbols::loadClassInternal_name() ||
duke@435 180 last_caller->name() == vmSymbols::loadClass_name())) {
duke@435 181 found_it = true;
acorn@1092 182 } else if (!vfst.at_end()) {
acorn@1092 183 if (vfst.method()->is_native()) {
acorn@1092 184 // JNI call
acorn@1092 185 found_it = true;
acorn@1092 186 }
duke@435 187 }
duke@435 188 if (found_it && !vfst.at_end()) {
duke@435 189 // found the caller
duke@435 190 caller = vfst.method()->method_holder();
duke@435 191 line_number = vfst.method()->line_number_from_bci(vfst.bci());
acorn@1092 192 if (line_number == -1) {
acorn@1092 193 // show method name if it's a native method
acorn@1092 194 trace = vfst.method()->name_and_sig_as_C_string();
acorn@1092 195 }
coleenp@4251 196 Symbol* s = caller->source_file_name();
duke@435 197 if (s != NULL) {
duke@435 198 source_file = s->as_C_string();
duke@435 199 }
duke@435 200 }
duke@435 201 }
duke@435 202 if (caller != NULL) {
duke@435 203 if (to_class != caller) {
coleenp@4251 204 const char * from = caller->external_name();
coleenp@4251 205 const char * to = to_class->external_name();
duke@435 206 // print in a single call to reduce interleaving between threads
duke@435 207 if (source_file != NULL) {
acorn@1092 208 tty->print("RESOLVE %s %s %s:%d (%s)\n", from, to, source_file, line_number, trace);
duke@435 209 } else {
acorn@1092 210 tty->print("RESOLVE %s %s (%s)\n", from, to, trace);
duke@435 211 }
duke@435 212 }
duke@435 213 }
duke@435 214 }
duke@435 215
coleenp@4037 216 void trace_class_resolution(Klass* to_class) {
duke@435 217 EXCEPTION_MARK;
duke@435 218 trace_class_resolution_impl(to_class, THREAD);
duke@435 219 if (HAS_PENDING_EXCEPTION) {
duke@435 220 CLEAR_PENDING_EXCEPTION;
duke@435 221 }
duke@435 222 }
duke@435 223
duke@435 224 // Wrapper to trace JVM functions
duke@435 225
duke@435 226 #ifdef ASSERT
duke@435 227 class JVMTraceWrapper : public StackObj {
duke@435 228 public:
drchase@6680 229 JVMTraceWrapper(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
duke@435 230 if (TraceJVMCalls) {
duke@435 231 va_list ap;
duke@435 232 va_start(ap, format);
duke@435 233 tty->print("JVM ");
duke@435 234 tty->vprint_cr(format, ap);
duke@435 235 va_end(ap);
duke@435 236 }
duke@435 237 }
duke@435 238 };
duke@435 239
duke@435 240 Histogram* JVMHistogram;
duke@435 241 volatile jint JVMHistogram_lock = 0;
duke@435 242
duke@435 243 class JVMHistogramElement : public HistogramElement {
duke@435 244 public:
duke@435 245 JVMHistogramElement(const char* name);
duke@435 246 };
duke@435 247
duke@435 248 JVMHistogramElement::JVMHistogramElement(const char* elementName) {
duke@435 249 _name = elementName;
duke@435 250 uintx count = 0;
duke@435 251
duke@435 252 while (Atomic::cmpxchg(1, &JVMHistogram_lock, 0) != 0) {
duke@435 253 while (OrderAccess::load_acquire(&JVMHistogram_lock) != 0) {
duke@435 254 count +=1;
duke@435 255 if ( (WarnOnStalledSpinLock > 0)
duke@435 256 && (count % WarnOnStalledSpinLock == 0)) {
duke@435 257 warning("JVMHistogram_lock seems to be stalled");
duke@435 258 }
duke@435 259 }
duke@435 260 }
duke@435 261
duke@435 262 if(JVMHistogram == NULL)
duke@435 263 JVMHistogram = new Histogram("JVM Call Counts",100);
duke@435 264
duke@435 265 JVMHistogram->add_element(this);
duke@435 266 Atomic::dec(&JVMHistogram_lock);
duke@435 267 }
duke@435 268
duke@435 269 #define JVMCountWrapper(arg) \
duke@435 270 static JVMHistogramElement* e = new JVMHistogramElement(arg); \
duke@435 271 if (e != NULL) e->increment_count(); // Due to bug in VC++, we need a NULL check here eventhough it should never happen!
duke@435 272
duke@435 273 #define JVMWrapper(arg1) JVMCountWrapper(arg1); JVMTraceWrapper(arg1)
duke@435 274 #define JVMWrapper2(arg1, arg2) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2)
duke@435 275 #define JVMWrapper3(arg1, arg2, arg3) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3)
duke@435 276 #define JVMWrapper4(arg1, arg2, arg3, arg4) JVMCountWrapper(arg1); JVMTraceWrapper(arg1, arg2, arg3, arg4)
duke@435 277 #else
duke@435 278 #define JVMWrapper(arg1)
duke@435 279 #define JVMWrapper2(arg1, arg2)
duke@435 280 #define JVMWrapper3(arg1, arg2, arg3)
duke@435 281 #define JVMWrapper4(arg1, arg2, arg3, arg4)
duke@435 282 #endif
duke@435 283
duke@435 284
duke@435 285 // Interface version /////////////////////////////////////////////////////////////////////
duke@435 286
duke@435 287
duke@435 288 JVM_LEAF(jint, JVM_GetInterfaceVersion())
duke@435 289 return JVM_INTERFACE_VERSION;
duke@435 290 JVM_END
duke@435 291
duke@435 292
duke@435 293 // java.lang.System //////////////////////////////////////////////////////////////////////
duke@435 294
duke@435 295
duke@435 296 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
duke@435 297 JVMWrapper("JVM_CurrentTimeMillis");
duke@435 298 return os::javaTimeMillis();
duke@435 299 JVM_END
duke@435 300
duke@435 301 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
duke@435 302 JVMWrapper("JVM_NanoTime");
duke@435 303 return os::javaTimeNanos();
duke@435 304 JVM_END
duke@435 305
duke@435 306
duke@435 307 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
duke@435 308 jobject dst, jint dst_pos, jint length))
duke@435 309 JVMWrapper("JVM_ArrayCopy");
duke@435 310 // Check if we have null pointers
duke@435 311 if (src == NULL || dst == NULL) {
duke@435 312 THROW(vmSymbols::java_lang_NullPointerException());
duke@435 313 }
duke@435 314 arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
duke@435 315 arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
duke@435 316 assert(s->is_oop(), "JVM_ArrayCopy: src not an oop");
duke@435 317 assert(d->is_oop(), "JVM_ArrayCopy: dst not an oop");
duke@435 318 // Do copy
hseigel@4278 319 s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread);
duke@435 320 JVM_END
duke@435 321
duke@435 322
duke@435 323 static void set_property(Handle props, const char* key, const char* value, TRAPS) {
duke@435 324 JavaValue r(T_OBJECT);
duke@435 325 // public synchronized Object put(Object key, Object value);
duke@435 326 HandleMark hm(THREAD);
duke@435 327 Handle key_str = java_lang_String::create_from_platform_dependent_str(key, CHECK);
duke@435 328 Handle value_str = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
duke@435 329 JavaCalls::call_virtual(&r,
duke@435 330 props,
never@1577 331 KlassHandle(THREAD, SystemDictionary::Properties_klass()),
coleenp@2497 332 vmSymbols::put_name(),
coleenp@2497 333 vmSymbols::object_object_object_signature(),
duke@435 334 key_str,
duke@435 335 value_str,
duke@435 336 THREAD);
duke@435 337 }
duke@435 338
duke@435 339
duke@435 340 #define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties));
duke@435 341
duke@435 342
duke@435 343 JVM_ENTRY(jobject, JVM_InitProperties(JNIEnv *env, jobject properties))
duke@435 344 JVMWrapper("JVM_InitProperties");
duke@435 345 ResourceMark rm;
duke@435 346
duke@435 347 Handle props(THREAD, JNIHandles::resolve_non_null(properties));
duke@435 348
duke@435 349 // System property list includes both user set via -D option and
duke@435 350 // jvm system specific properties.
duke@435 351 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) {
duke@435 352 PUTPROP(props, p->key(), p->value());
duke@435 353 }
duke@435 354
duke@435 355 // Convert the -XX:MaxDirectMemorySize= command line flag
duke@435 356 // to the sun.nio.MaxDirectMemorySize property.
duke@435 357 // Do this after setting user properties to prevent people
duke@435 358 // from setting the value with a -D option, as requested.
duke@435 359 {
dholmes@3902 360 if (FLAG_IS_DEFAULT(MaxDirectMemorySize)) {
dholmes@3902 361 PUTPROP(props, "sun.nio.MaxDirectMemorySize", "-1");
dholmes@3902 362 } else {
dholmes@3902 363 char as_chars[256];
dholmes@3902 364 jio_snprintf(as_chars, sizeof(as_chars), UINTX_FORMAT, MaxDirectMemorySize);
dholmes@3902 365 PUTPROP(props, "sun.nio.MaxDirectMemorySize", as_chars);
dholmes@3902 366 }
duke@435 367 }
duke@435 368
duke@435 369 // JVM monitoring and management support
duke@435 370 // Add the sun.management.compiler property for the compiler's name
duke@435 371 {
duke@435 372 #undef CSIZE
duke@435 373 #if defined(_LP64) || defined(_WIN64)
duke@435 374 #define CSIZE "64-Bit "
duke@435 375 #else
duke@435 376 #define CSIZE
duke@435 377 #endif // 64bit
duke@435 378
duke@435 379 #ifdef TIERED
duke@435 380 const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers";
duke@435 381 #else
duke@435 382 #if defined(COMPILER1)
duke@435 383 const char* compiler_name = "HotSpot " CSIZE "Client Compiler";
duke@435 384 #elif defined(COMPILER2)
duke@435 385 const char* compiler_name = "HotSpot " CSIZE "Server Compiler";
duke@435 386 #else
duke@435 387 const char* compiler_name = "";
duke@435 388 #endif // compilers
duke@435 389 #endif // TIERED
duke@435 390
duke@435 391 if (*compiler_name != '\0' &&
duke@435 392 (Arguments::mode() != Arguments::_int)) {
duke@435 393 PUTPROP(props, "sun.management.compiler", compiler_name);
duke@435 394 }
duke@435 395 }
duke@435 396
iklam@7322 397 const char* enableSharedLookupCache = "false";
iklam@7322 398 #if INCLUDE_CDS
iklam@7322 399 if (ClassLoaderExt::is_lookup_cache_enabled()) {
iklam@7322 400 enableSharedLookupCache = "true";
iklam@7322 401 }
iklam@7322 402 #endif
iklam@7322 403 PUTPROP(props, "sun.cds.enableSharedLookupCache", enableSharedLookupCache);
iklam@7322 404
duke@435 405 return properties;
duke@435 406 JVM_END
duke@435 407
duke@435 408
sla@6705 409 /*
sla@6705 410 * Return the temporary directory that the VM uses for the attach
sla@6705 411 * and perf data files.
sla@6705 412 *
sla@6705 413 * It is important that this directory is well-known and the
sla@6705 414 * same for all VM instances. It cannot be affected by configuration
sla@6705 415 * variables such as java.io.tmpdir.
sla@6705 416 */
sla@6705 417 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
sla@6705 418 JVMWrapper("JVM_GetTemporaryDirectory");
sla@6705 419 HandleMark hm(THREAD);
sla@6705 420 const char* temp_dir = os::get_temp_directory();
sla@6705 421 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
sla@6705 422 return (jstring) JNIHandles::make_local(env, h());
sla@6705 423 JVM_END
sla@6705 424
sla@6705 425
duke@435 426 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
duke@435 427
duke@435 428 extern volatile jint vm_created;
duke@435 429
duke@435 430 JVM_ENTRY_NO_ENV(void, JVM_Exit(jint code))
duke@435 431 if (vm_created != 0 && (code == 0)) {
duke@435 432 // The VM is about to exit. We call back into Java to check whether finalizers should be run
duke@435 433 Universe::run_finalizers_on_exit();
duke@435 434 }
duke@435 435 before_exit(thread);
duke@435 436 vm_exit(code);
duke@435 437 JVM_END
duke@435 438
duke@435 439
duke@435 440 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
duke@435 441 before_exit(thread);
duke@435 442 vm_exit(code);
duke@435 443 JVM_END
duke@435 444
duke@435 445
duke@435 446 JVM_LEAF(void, JVM_OnExit(void (*func)(void)))
duke@435 447 register_on_exit_function(func);
duke@435 448 JVM_END
duke@435 449
duke@435 450
duke@435 451 JVM_ENTRY_NO_ENV(void, JVM_GC(void))
duke@435 452 JVMWrapper("JVM_GC");
duke@435 453 if (!DisableExplicitGC) {
duke@435 454 Universe::heap()->collect(GCCause::_java_lang_system_gc);
duke@435 455 }
duke@435 456 JVM_END
duke@435 457
duke@435 458
duke@435 459 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))
duke@435 460 JVMWrapper("JVM_MaxObjectInspectionAge");
duke@435 461 return Universe::heap()->millis_since_last_gc();
duke@435 462 JVM_END
duke@435 463
duke@435 464
duke@435 465 JVM_LEAF(void, JVM_TraceInstructions(jboolean on))
duke@435 466 if (PrintJVMWarnings) warning("JVM_TraceInstructions not supported");
duke@435 467 JVM_END
duke@435 468
duke@435 469
duke@435 470 JVM_LEAF(void, JVM_TraceMethodCalls(jboolean on))
duke@435 471 if (PrintJVMWarnings) warning("JVM_TraceMethodCalls not supported");
duke@435 472 JVM_END
duke@435 473
duke@435 474 static inline jlong convert_size_t_to_jlong(size_t val) {
duke@435 475 // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
duke@435 476 NOT_LP64 (return (jlong)val;)
duke@435 477 LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);)
duke@435 478 }
duke@435 479
duke@435 480 JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void))
duke@435 481 JVMWrapper("JVM_TotalMemory");
duke@435 482 size_t n = Universe::heap()->capacity();
duke@435 483 return convert_size_t_to_jlong(n);
duke@435 484 JVM_END
duke@435 485
duke@435 486
duke@435 487 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
duke@435 488 JVMWrapper("JVM_FreeMemory");
duke@435 489 CollectedHeap* ch = Universe::heap();
ysr@777 490 size_t n;
ysr@777 491 {
ysr@777 492 MutexLocker x(Heap_lock);
ysr@777 493 n = ch->capacity() - ch->used();
ysr@777 494 }
duke@435 495 return convert_size_t_to_jlong(n);
duke@435 496 JVM_END
duke@435 497
duke@435 498
duke@435 499 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
duke@435 500 JVMWrapper("JVM_MaxMemory");
duke@435 501 size_t n = Universe::heap()->max_capacity();
duke@435 502 return convert_size_t_to_jlong(n);
duke@435 503 JVM_END
duke@435 504
duke@435 505
duke@435 506 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
duke@435 507 JVMWrapper("JVM_ActiveProcessorCount");
duke@435 508 return os::active_processor_count();
duke@435 509 JVM_END
duke@435 510
duke@435 511
duke@435 512
duke@435 513 // java.lang.Throwable //////////////////////////////////////////////////////
duke@435 514
duke@435 515
duke@435 516 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
duke@435 517 JVMWrapper("JVM_FillInStackTrace");
duke@435 518 Handle exception(thread, JNIHandles::resolve_non_null(receiver));
duke@435 519 java_lang_Throwable::fill_in_stack_trace(exception);
duke@435 520 JVM_END
duke@435 521
duke@435 522
duke@435 523 JVM_ENTRY(jint, JVM_GetStackTraceDepth(JNIEnv *env, jobject throwable))
duke@435 524 JVMWrapper("JVM_GetStackTraceDepth");
duke@435 525 oop exception = JNIHandles::resolve(throwable);
duke@435 526 return java_lang_Throwable::get_stack_trace_depth(exception, THREAD);
duke@435 527 JVM_END
duke@435 528
duke@435 529
duke@435 530 JVM_ENTRY(jobject, JVM_GetStackTraceElement(JNIEnv *env, jobject throwable, jint index))
duke@435 531 JVMWrapper("JVM_GetStackTraceElement");
duke@435 532 JvmtiVMObjectAllocEventCollector oam; // This ctor (throughout this module) may trigger a safepoint/GC
duke@435 533 oop exception = JNIHandles::resolve(throwable);
duke@435 534 oop element = java_lang_Throwable::get_stack_trace_element(exception, index, CHECK_NULL);
duke@435 535 return JNIHandles::make_local(env, element);
duke@435 536 JVM_END
duke@435 537
duke@435 538
duke@435 539 // java.lang.Object ///////////////////////////////////////////////
duke@435 540
duke@435 541
duke@435 542 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
duke@435 543 JVMWrapper("JVM_IHashCode");
duke@435 544 // as implemented in the classic virtual machine; return 0 if object is NULL
duke@435 545 return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
duke@435 546 JVM_END
duke@435 547
duke@435 548
duke@435 549 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
duke@435 550 JVMWrapper("JVM_MonitorWait");
duke@435 551 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
duke@435 552 JavaThreadInObjectWaitState jtiows(thread, ms != 0);
duke@435 553 if (JvmtiExport::should_post_monitor_wait()) {
duke@435 554 JvmtiExport::post_monitor_wait((JavaThread *)THREAD, (oop)obj(), ms);
dcubed@6335 555
dcubed@6335 556 // The current thread already owns the monitor and it has not yet
dcubed@6335 557 // been added to the wait queue so the current thread cannot be
dcubed@6335 558 // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
dcubed@6335 559 // event handler cannot accidentally consume an unpark() meant for
dcubed@6335 560 // the ParkEvent associated with this ObjectMonitor.
duke@435 561 }
duke@435 562 ObjectSynchronizer::wait(obj, ms, CHECK);
duke@435 563 JVM_END
duke@435 564
duke@435 565
duke@435 566 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
duke@435 567 JVMWrapper("JVM_MonitorNotify");
duke@435 568 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
duke@435 569 ObjectSynchronizer::notify(obj, CHECK);
duke@435 570 JVM_END
duke@435 571
duke@435 572
duke@435 573 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
duke@435 574 JVMWrapper("JVM_MonitorNotifyAll");
duke@435 575 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
duke@435 576 ObjectSynchronizer::notifyall(obj, CHECK);
duke@435 577 JVM_END
duke@435 578
duke@435 579
duke@435 580 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
duke@435 581 JVMWrapper("JVM_Clone");
duke@435 582 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
duke@435 583 const KlassHandle klass (THREAD, obj->klass());
duke@435 584 JvmtiVMObjectAllocEventCollector oam;
duke@435 585
duke@435 586 #ifdef ASSERT
duke@435 587 // Just checking that the cloneable flag is set correct
coleenp@4037 588 if (obj->is_array()) {
duke@435 589 guarantee(klass->is_cloneable(), "all arrays are cloneable");
duke@435 590 } else {
duke@435 591 guarantee(obj->is_instance(), "should be instanceOop");
never@1577 592 bool cloneable = klass->is_subtype_of(SystemDictionary::Cloneable_klass());
duke@435 593 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
duke@435 594 }
duke@435 595 #endif
duke@435 596
duke@435 597 // Check if class of obj supports the Cloneable interface.
duke@435 598 // All arrays are considered to be cloneable (See JLS 20.1.5)
duke@435 599 if (!klass->is_cloneable()) {
duke@435 600 ResourceMark rm(THREAD);
duke@435 601 THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
duke@435 602 }
duke@435 603
duke@435 604 // Make shallow object copy
duke@435 605 const int size = obj->size();
coleenp@7391 606 oop new_obj_oop = NULL;
coleenp@4037 607 if (obj->is_array()) {
duke@435 608 const int length = ((arrayOop)obj())->length();
coleenp@7391 609 new_obj_oop = CollectedHeap::array_allocate(klass, size, length, CHECK_NULL);
duke@435 610 } else {
coleenp@7391 611 new_obj_oop = CollectedHeap::obj_allocate(klass, size, CHECK_NULL);
duke@435 612 }
coleenp@7391 613
duke@435 614 // 4839641 (4840070): We must do an oop-atomic copy, because if another thread
duke@435 615 // is modifying a reference field in the clonee, a non-oop-atomic copy might
duke@435 616 // be suspended in the middle of copying the pointer and end up with parts
duke@435 617 // of two different pointers in the field. Subsequent dereferences will crash.
duke@435 618 // 4846409: an oop-copy of objects with long or double fields or arrays of same
duke@435 619 // won't copy the longs/doubles atomically in 32-bit vm's, so we copy jlongs instead
duke@435 620 // of oops. We know objects are aligned on a minimum of an jlong boundary.
duke@435 621 // The same is true of StubRoutines::object_copy and the various oop_copy
duke@435 622 // variants, and of the code generated by the inline_native_clone intrinsic.
duke@435 623 assert(MinObjAlignmentInBytes >= BytesPerLong, "objects misaligned");
coleenp@7391 624 Copy::conjoint_jlongs_atomic((jlong*)obj(), (jlong*)new_obj_oop,
duke@435 625 (size_t)align_object_size(size) / HeapWordsPerLong);
duke@435 626 // Clear the header
coleenp@7391 627 new_obj_oop->init_mark();
duke@435 628
duke@435 629 // Store check (mark entire object and let gc sort it out)
duke@435 630 BarrierSet* bs = Universe::heap()->barrier_set();
duke@435 631 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
coleenp@7391 632 bs->write_region(MemRegion((HeapWord*)new_obj_oop, size));
coleenp@7391 633
coleenp@7391 634 Handle new_obj(THREAD, new_obj_oop);
coleenp@7391 635 // Special handling for MemberNames. Since they contain Method* metadata, they
coleenp@7391 636 // must be registered so that RedefineClasses can fix metadata contained in them.
coleenp@7391 637 if (java_lang_invoke_MemberName::is_instance(new_obj()) &&
coleenp@7391 638 java_lang_invoke_MemberName::is_method(new_obj())) {
coleenp@7391 639 Method* method = (Method*)java_lang_invoke_MemberName::vmtarget(new_obj());
coleenp@7391 640 // MemberName may be unresolved, so doesn't need registration until resolved.
coleenp@7391 641 if (method != NULL) {
coleenp@7391 642 methodHandle m(THREAD, method);
coleenp@7391 643 // This can safepoint and redefine method, so need both new_obj and method
coleenp@7391 644 // in a handle, for two different reasons. new_obj can move, method can be
coleenp@7391 645 // deleted if nothing is using it on the stack.
coleenp@7391 646 m->method_holder()->add_member_name(new_obj());
coleenp@7391 647 }
coleenp@7391 648 }
duke@435 649
duke@435 650 // Caution: this involves a java upcall, so the clone should be
duke@435 651 // "gc-robust" by this stage.
duke@435 652 if (klass->has_finalizer()) {
duke@435 653 assert(obj->is_instance(), "should be instanceOop");
coleenp@7391 654 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
coleenp@7391 655 new_obj = Handle(THREAD, new_obj_oop);
duke@435 656 }
duke@435 657
coleenp@7391 658 return JNIHandles::make_local(env, new_obj());
duke@435 659 JVM_END
duke@435 660
duke@435 661 // java.lang.Compiler ////////////////////////////////////////////////////
duke@435 662
duke@435 663 // The initial cuts of the HotSpot VM will not support JITs, and all existing
duke@435 664 // JITs would need extensive changes to work with HotSpot. The JIT-related JVM
duke@435 665 // functions are all silently ignored unless JVM warnings are printed.
duke@435 666
duke@435 667 JVM_LEAF(void, JVM_InitializeCompiler (JNIEnv *env, jclass compCls))
duke@435 668 if (PrintJVMWarnings) warning("JVM_InitializeCompiler not supported");
duke@435 669 JVM_END
duke@435 670
duke@435 671
duke@435 672 JVM_LEAF(jboolean, JVM_IsSilentCompiler(JNIEnv *env, jclass compCls))
duke@435 673 if (PrintJVMWarnings) warning("JVM_IsSilentCompiler not supported");
duke@435 674 return JNI_FALSE;
duke@435 675 JVM_END
duke@435 676
duke@435 677
duke@435 678 JVM_LEAF(jboolean, JVM_CompileClass(JNIEnv *env, jclass compCls, jclass cls))
duke@435 679 if (PrintJVMWarnings) warning("JVM_CompileClass not supported");
duke@435 680 return JNI_FALSE;
duke@435 681 JVM_END
duke@435 682
duke@435 683
duke@435 684 JVM_LEAF(jboolean, JVM_CompileClasses(JNIEnv *env, jclass cls, jstring jname))
duke@435 685 if (PrintJVMWarnings) warning("JVM_CompileClasses not supported");
duke@435 686 return JNI_FALSE;
duke@435 687 JVM_END
duke@435 688
duke@435 689
duke@435 690 JVM_LEAF(jobject, JVM_CompilerCommand(JNIEnv *env, jclass compCls, jobject arg))
duke@435 691 if (PrintJVMWarnings) warning("JVM_CompilerCommand not supported");
duke@435 692 return NULL;
duke@435 693 JVM_END
duke@435 694
duke@435 695
duke@435 696 JVM_LEAF(void, JVM_EnableCompiler(JNIEnv *env, jclass compCls))
duke@435 697 if (PrintJVMWarnings) warning("JVM_EnableCompiler not supported");
duke@435 698 JVM_END
duke@435 699
duke@435 700
duke@435 701 JVM_LEAF(void, JVM_DisableCompiler(JNIEnv *env, jclass compCls))
duke@435 702 if (PrintJVMWarnings) warning("JVM_DisableCompiler not supported");
duke@435 703 JVM_END
duke@435 704
duke@435 705
duke@435 706
duke@435 707 // Error message support //////////////////////////////////////////////////////
duke@435 708
duke@435 709 JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len))
duke@435 710 JVMWrapper("JVM_GetLastErrorString");
ikrylov@2322 711 return (jint)os::lasterror(buf, len);
duke@435 712 JVM_END
duke@435 713
duke@435 714
duke@435 715 // java.io.File ///////////////////////////////////////////////////////////////
duke@435 716
duke@435 717 JVM_LEAF(char*, JVM_NativePath(char* path))
duke@435 718 JVMWrapper2("JVM_NativePath (%s)", path);
ikrylov@2322 719 return os::native_path(path);
duke@435 720 JVM_END
duke@435 721
duke@435 722
duke@435 723 // Misc. class handling ///////////////////////////////////////////////////////////
duke@435 724
duke@435 725
duke@435 726 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
duke@435 727 JVMWrapper("JVM_GetCallerClass");
twisti@4866 728
dholmes@5849 729 // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
dholmes@5849 730 // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
dholmes@5849 731 // temporarily for existing code to use until a replacement API is defined.
dholmes@5849 732 if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
twisti@4866 733 Klass* k = thread->security_get_caller_class(depth);
twisti@4866 734 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
twisti@4866 735 }
twisti@4866 736
twisti@4866 737 // Getting the class of the caller frame.
twisti@4866 738 //
twisti@4866 739 // The call stack at this point looks something like this:
twisti@4866 740 //
twisti@4866 741 // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
twisti@4866 742 // [1] [ @CallerSensitive API.method ]
twisti@4866 743 // [.] [ (skipped intermediate frames) ]
twisti@4866 744 // [n] [ caller ]
twisti@4866 745 vframeStream vfst(thread);
twisti@4866 746 // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass
twisti@4866 747 for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) {
twisti@4866 748 Method* m = vfst.method();
twisti@4866 749 assert(m != NULL, "sanity");
twisti@4866 750 switch (n) {
twisti@4866 751 case 0:
twisti@4866 752 // This must only be called from Reflection.getCallerClass
twisti@4866 753 if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) {
twisti@4866 754 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass");
twisti@4866 755 }
twisti@4866 756 // fall-through
twisti@4866 757 case 1:
twisti@4866 758 // Frame 0 and 1 must be caller sensitive.
twisti@4866 759 if (!m->caller_sensitive()) {
twisti@4866 760 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n));
twisti@4866 761 }
twisti@4866 762 break;
twisti@4866 763 default:
twisti@4866 764 if (!m->is_ignored_by_security_stack_walk()) {
twisti@4866 765 // We have reached the desired frame; return the holder class.
twisti@4866 766 return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror());
twisti@4866 767 }
twisti@4866 768 break;
twisti@4866 769 }
twisti@4866 770 }
twisti@4866 771 return NULL;
duke@435 772 JVM_END
duke@435 773
duke@435 774
duke@435 775 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
duke@435 776 JVMWrapper("JVM_FindPrimitiveClass");
duke@435 777 oop mirror = NULL;
duke@435 778 BasicType t = name2type(utf);
duke@435 779 if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
duke@435 780 mirror = Universe::java_mirror(t);
duke@435 781 }
duke@435 782 if (mirror == NULL) {
duke@435 783 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
duke@435 784 } else {
duke@435 785 return (jclass) JNIHandles::make_local(env, mirror);
duke@435 786 }
duke@435 787 JVM_END
duke@435 788
duke@435 789
duke@435 790 JVM_ENTRY(void, JVM_ResolveClass(JNIEnv* env, jclass cls))
duke@435 791 JVMWrapper("JVM_ResolveClass");
duke@435 792 if (PrintJVMWarnings) warning("JVM_ResolveClass not implemented");
duke@435 793 JVM_END
duke@435 794
mchung@1313 795
iklam@7322 796 JVM_ENTRY(jboolean, JVM_KnownToNotExist(JNIEnv *env, jobject loader, const char *classname))
iklam@7322 797 JVMWrapper("JVM_KnownToNotExist");
iklam@7322 798 #if INCLUDE_CDS
iklam@7322 799 return ClassLoaderExt::known_to_not_exist(env, loader, classname, CHECK_(false));
iklam@7322 800 #else
iklam@7322 801 return false;
iklam@7322 802 #endif
iklam@7322 803 JVM_END
iklam@7322 804
iklam@7322 805
iklam@7322 806 JVM_ENTRY(jobjectArray, JVM_GetResourceLookupCacheURLs(JNIEnv *env, jobject loader))
iklam@7322 807 JVMWrapper("JVM_GetResourceLookupCacheURLs");
iklam@7322 808 #if INCLUDE_CDS
iklam@7322 809 return ClassLoaderExt::get_lookup_cache_urls(env, loader, CHECK_NULL);
iklam@7322 810 #else
iklam@7322 811 return NULL;
iklam@7322 812 #endif
iklam@7322 813 JVM_END
iklam@7322 814
iklam@7322 815
iklam@7322 816 JVM_ENTRY(jintArray, JVM_GetResourceLookupCache(JNIEnv *env, jobject loader, const char *resource_name))
iklam@7322 817 JVMWrapper("JVM_GetResourceLookupCache");
iklam@7322 818 #if INCLUDE_CDS
iklam@7322 819 return ClassLoaderExt::get_lookup_cache(env, loader, resource_name, CHECK_NULL);
iklam@7322 820 #else
iklam@7322 821 return NULL;
iklam@7322 822 #endif
iklam@7322 823 JVM_END
iklam@7322 824
iklam@7322 825
mchung@1313 826 // Returns a class loaded by the bootstrap class loader; or null
mchung@1313 827 // if not found. ClassNotFoundException is not thrown.
mchung@1313 828 //
ksrini@661 829 // Rationale behind JVM_FindClassFromBootLoader
ksrini@661 830 // a> JVM_FindClassFromClassLoader was never exported in the export tables.
ksrini@661 831 // b> because of (a) java.dll has a direct dependecy on the unexported
ksrini@661 832 // private symbol "_JVM_FindClassFromClassLoader@20".
ksrini@661 833 // c> the launcher cannot use the private symbol as it dynamically opens
ksrini@661 834 // the entry point, so if something changes, the launcher will fail
ksrini@661 835 // unexpectedly at runtime, it is safest for the launcher to dlopen a
ksrini@661 836 // stable exported interface.
ksrini@661 837 // d> re-exporting JVM_FindClassFromClassLoader as public, will cause its
ksrini@661 838 // signature to change from _JVM_FindClassFromClassLoader@20 to
ksrini@661 839 // JVM_FindClassFromClassLoader and will not be backward compatible
ksrini@661 840 // with older JDKs.
ksrini@661 841 // Thus a public/stable exported entry point is the right solution,
ksrini@661 842 // public here means public in linker semantics, and is exported only
ksrini@661 843 // to the JDK, and is not intended to be a public API.
ksrini@661 844
ksrini@661 845 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
mchung@1313 846 const char* name))
mchung@1313 847 JVMWrapper2("JVM_FindClassFromBootLoader %s", name);
mchung@1313 848
mchung@1313 849 // Java libraries should ensure that name is never null...
coleenp@2497 850 if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
mchung@1313 851 // It's impossible to create this class; the name cannot fit
mchung@1313 852 // into the constant pool.
mchung@1313 853 return NULL;
mchung@1313 854 }
mchung@1313 855
coleenp@2497 856 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
coleenp@4037 857 Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL);
mchung@1313 858 if (k == NULL) {
mchung@1313 859 return NULL;
mchung@1313 860 }
mchung@1313 861
mchung@1313 862 if (TraceClassResolution) {
mchung@1313 863 trace_class_resolution(k);
mchung@1313 864 }
hseigel@4278 865 return (jclass) JNIHandles::make_local(env, k->java_mirror());
ksrini@661 866 JVM_END
duke@435 867
coleenp@6823 868 // Not used; JVM_FindClassFromCaller replaces this.
duke@435 869 JVM_ENTRY(jclass, JVM_FindClassFromClassLoader(JNIEnv* env, const char* name,
duke@435 870 jboolean init, jobject loader,
duke@435 871 jboolean throwError))
duke@435 872 JVMWrapper3("JVM_FindClassFromClassLoader %s throw %s", name,
duke@435 873 throwError ? "error" : "exception");
mchung@1313 874 // Java libraries should ensure that name is never null...
coleenp@2497 875 if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
mchung@1313 876 // It's impossible to create this class; the name cannot fit
mchung@1313 877 // into the constant pool.
mchung@1313 878 if (throwError) {
mchung@1313 879 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
mchung@1313 880 } else {
mchung@1313 881 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
mchung@1313 882 }
mchung@1313 883 }
coleenp@2497 884 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
mchung@1313 885 Handle h_loader(THREAD, JNIHandles::resolve(loader));
mchung@1313 886 jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
mchung@1313 887 Handle(), throwError, THREAD);
mchung@1313 888
mchung@1313 889 if (TraceClassResolution && result != NULL) {
coleenp@4037 890 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
mchung@1313 891 }
mchung@1313 892 return result;
duke@435 893 JVM_END
duke@435 894
coleenp@6823 895 // Find a class with this name in this loader, using the caller's protection domain.
coleenp@6823 896 JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name,
coleenp@6823 897 jboolean init, jobject loader,
coleenp@6823 898 jclass caller))
coleenp@6823 899 JVMWrapper2("JVM_FindClassFromCaller %s throws ClassNotFoundException", name);
coleenp@6823 900 // Java libraries should ensure that name is never null...
coleenp@6823 901 if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
coleenp@6823 902 // It's impossible to create this class; the name cannot fit
coleenp@6823 903 // into the constant pool.
coleenp@6823 904 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), name);
coleenp@6823 905 }
coleenp@6823 906
coleenp@6823 907 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
coleenp@6823 908
coleenp@6823 909 oop loader_oop = JNIHandles::resolve(loader);
coleenp@6823 910 oop from_class = JNIHandles::resolve(caller);
coleenp@6823 911 oop protection_domain = NULL;
coleenp@6823 912 // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get
coleenp@6823 913 // NPE. Put it in another way, the bootstrap class loader has all permission and
coleenp@6823 914 // thus no checkPackageAccess equivalence in the VM class loader.
coleenp@6823 915 // The caller is also passed as NULL by the java code if there is no security
coleenp@6823 916 // manager to avoid the performance cost of getting the calling class.
coleenp@6823 917 if (from_class != NULL && loader_oop != NULL) {
coleenp@6823 918 protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
coleenp@6823 919 }
coleenp@6823 920
coleenp@6823 921 Handle h_loader(THREAD, loader_oop);
coleenp@6823 922 Handle h_prot(THREAD, protection_domain);
coleenp@6823 923 jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
coleenp@6823 924 h_prot, false, THREAD);
coleenp@6823 925
coleenp@6823 926 if (TraceClassResolution && result != NULL) {
coleenp@6823 927 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
coleenp@6823 928 }
coleenp@6823 929 return result;
coleenp@6823 930 JVM_END
duke@435 931
duke@435 932 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
duke@435 933 jboolean init, jclass from))
duke@435 934 JVMWrapper2("JVM_FindClassFromClass %s", name);
coleenp@2497 935 if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
duke@435 936 // It's impossible to create this class; the name cannot fit
duke@435 937 // into the constant pool.
duke@435 938 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
duke@435 939 }
coleenp@2497 940 TempNewSymbol h_name = SymbolTable::new_symbol(name, CHECK_NULL);
duke@435 941 oop from_class_oop = JNIHandles::resolve(from);
coleenp@4037 942 Klass* from_class = (from_class_oop == NULL)
coleenp@4037 943 ? (Klass*)NULL
coleenp@4037 944 : java_lang_Class::as_Klass(from_class_oop);
duke@435 945 oop class_loader = NULL;
duke@435 946 oop protection_domain = NULL;
duke@435 947 if (from_class != NULL) {
hseigel@4278 948 class_loader = from_class->class_loader();
hseigel@4278 949 protection_domain = from_class->protection_domain();
duke@435 950 }
duke@435 951 Handle h_loader(THREAD, class_loader);
duke@435 952 Handle h_prot (THREAD, protection_domain);
duke@435 953 jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
duke@435 954 h_prot, true, thread);
duke@435 955
duke@435 956 if (TraceClassResolution && result != NULL) {
duke@435 957 // this function is generally only used for class loading during verification.
duke@435 958 ResourceMark rm;
duke@435 959 oop from_mirror = JNIHandles::resolve_non_null(from);
coleenp@4037 960 Klass* from_class = java_lang_Class::as_Klass(from_mirror);
hseigel@4278 961 const char * from_name = from_class->external_name();
duke@435 962
duke@435 963 oop mirror = JNIHandles::resolve_non_null(result);
coleenp@4037 964 Klass* to_class = java_lang_Class::as_Klass(mirror);
hseigel@4278 965 const char * to = to_class->external_name();
duke@435 966 tty->print("RESOLVE %s %s (verification)\n", from_name, to);
duke@435 967 }
duke@435 968
duke@435 969 return result;
duke@435 970 JVM_END
duke@435 971
duke@435 972 static void is_lock_held_by_thread(Handle loader, PerfCounter* counter, TRAPS) {
duke@435 973 if (loader.is_null()) {
duke@435 974 return;
duke@435 975 }
duke@435 976
duke@435 977 // check whether the current caller thread holds the lock or not.
duke@435 978 // If not, increment the corresponding counter
duke@435 979 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader) !=
duke@435 980 ObjectSynchronizer::owner_self) {
duke@435 981 counter->inc();
duke@435 982 }
duke@435 983 }
duke@435 984
duke@435 985 // common code for JVM_DefineClass() and JVM_DefineClassWithSource()
acorn@1408 986 // and JVM_DefineClassWithSourceCond()
acorn@1408 987 static jclass jvm_define_class_common(JNIEnv *env, const char *name,
acorn@1408 988 jobject loader, const jbyte *buf,
acorn@1408 989 jsize len, jobject pd, const char *source,
acorn@1408 990 jboolean verify, TRAPS) {
jrose@866 991 if (source == NULL) source = "__JVM_DefineClass__";
duke@435 992
mchung@1310 993 assert(THREAD->is_Java_thread(), "must be a JavaThread");
mchung@1310 994 JavaThread* jt = (JavaThread*) THREAD;
mchung@1310 995
mchung@1310 996 PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(),
mchung@1310 997 ClassLoader::perf_define_appclass_selftime(),
mchung@1310 998 ClassLoader::perf_define_appclasses(),
mchung@1310 999 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@1310 1000 jt->get_thread_stat()->perf_timers_addr(),
mchung@1310 1001 PerfClassTraceTime::DEFINE_CLASS);
mchung@1310 1002
mchung@1310 1003 if (UsePerfData) {
mchung@1310 1004 ClassLoader::perf_app_classfile_bytes_read()->inc(len);
mchung@1310 1005 }
mchung@1310 1006
duke@435 1007 // Since exceptions can be thrown, class initialization can take place
duke@435 1008 // if name is NULL no check for class name in .class stream has to be made.
coleenp@2497 1009 TempNewSymbol class_name = NULL;
duke@435 1010 if (name != NULL) {
duke@435 1011 const int str_len = (int)strlen(name);
coleenp@2497 1012 if (str_len > Symbol::max_length()) {
duke@435 1013 // It's impossible to create this class; the name cannot fit
duke@435 1014 // into the constant pool.
duke@435 1015 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name);
duke@435 1016 }
coleenp@2497 1017 class_name = SymbolTable::new_symbol(name, str_len, CHECK_NULL);
duke@435 1018 }
duke@435 1019
duke@435 1020 ResourceMark rm(THREAD);
duke@435 1021 ClassFileStream st((u1*) buf, len, (char *)source);
duke@435 1022 Handle class_loader (THREAD, JNIHandles::resolve(loader));
duke@435 1023 if (UsePerfData) {
duke@435 1024 is_lock_held_by_thread(class_loader,
duke@435 1025 ClassLoader::sync_JVMDefineClassLockFreeCounter(),
duke@435 1026 THREAD);
duke@435 1027 }
duke@435 1028 Handle protection_domain (THREAD, JNIHandles::resolve(pd));
coleenp@4037 1029 Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader,
duke@435 1030 protection_domain, &st,
acorn@1408 1031 verify != 0,
duke@435 1032 CHECK_NULL);
duke@435 1033
duke@435 1034 if (TraceClassResolution && k != NULL) {
duke@435 1035 trace_class_resolution(k);
duke@435 1036 }
duke@435 1037
hseigel@4278 1038 return (jclass) JNIHandles::make_local(env, k->java_mirror());
duke@435 1039 }
duke@435 1040
duke@435 1041
duke@435 1042 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
duke@435 1043 JVMWrapper2("JVM_DefineClass %s", name);
duke@435 1044
acorn@1408 1045 return jvm_define_class_common(env, name, loader, buf, len, pd, NULL, true, THREAD);
duke@435 1046 JVM_END
duke@435 1047
duke@435 1048
duke@435 1049 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
duke@435 1050 JVMWrapper2("JVM_DefineClassWithSource %s", name);
duke@435 1051
acorn@1408 1052 return jvm_define_class_common(env, name, loader, buf, len, pd, source, true, THREAD);
acorn@1408 1053 JVM_END
acorn@1408 1054
acorn@1408 1055 JVM_ENTRY(jclass, JVM_DefineClassWithSourceCond(JNIEnv *env, const char *name,
acorn@1408 1056 jobject loader, const jbyte *buf,
acorn@1408 1057 jsize len, jobject pd,
acorn@1408 1058 const char *source, jboolean verify))
acorn@1408 1059 JVMWrapper2("JVM_DefineClassWithSourceCond %s", name);
acorn@1408 1060
acorn@1408 1061 return jvm_define_class_common(env, name, loader, buf, len, pd, source, verify, THREAD);
acorn@1408 1062 JVM_END
duke@435 1063
duke@435 1064 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
duke@435 1065 JVMWrapper("JVM_FindLoadedClass");
duke@435 1066 ResourceMark rm(THREAD);
duke@435 1067
duke@435 1068 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
duke@435 1069 Handle string = java_lang_String::internalize_classname(h_name, CHECK_NULL);
duke@435 1070
duke@435 1071 const char* str = java_lang_String::as_utf8_string(string());
duke@435 1072 // Sanity check, don't expect null
duke@435 1073 if (str == NULL) return NULL;
duke@435 1074
duke@435 1075 const int str_len = (int)strlen(str);
coleenp@2497 1076 if (str_len > Symbol::max_length()) {
duke@435 1077 // It's impossible to create this class; the name cannot fit
duke@435 1078 // into the constant pool.
duke@435 1079 return NULL;
duke@435 1080 }
coleenp@2497 1081 TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len, CHECK_NULL);
duke@435 1082
duke@435 1083 // Security Note:
duke@435 1084 // The Java level wrapper will perform the necessary security check allowing
duke@435 1085 // us to pass the NULL as the initiating class loader.
duke@435 1086 Handle h_loader(THREAD, JNIHandles::resolve(loader));
duke@435 1087 if (UsePerfData) {
duke@435 1088 is_lock_held_by_thread(h_loader,
duke@435 1089 ClassLoader::sync_JVMFindLoadedClassLockFreeCounter(),
duke@435 1090 THREAD);
duke@435 1091 }
duke@435 1092
coleenp@4037 1093 Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
duke@435 1094 h_loader,
duke@435 1095 Handle(),
duke@435 1096 CHECK_NULL);
iklam@7089 1097 #if INCLUDE_CDS
iklam@7089 1098 if (k == NULL) {
iklam@7089 1099 // If the class is not already loaded, try to see if it's in the shared
iklam@7089 1100 // archive for the current classloader (h_loader).
iklam@7089 1101 instanceKlassHandle ik = SystemDictionaryShared::find_or_load_shared_class(
iklam@7089 1102 klass_name, h_loader, CHECK_NULL);
iklam@7089 1103 k = ik();
iklam@7089 1104 }
iklam@7089 1105 #endif
duke@435 1106 return (k == NULL) ? NULL :
hseigel@4278 1107 (jclass) JNIHandles::make_local(env, k->java_mirror());
duke@435 1108 JVM_END
duke@435 1109
duke@435 1110
duke@435 1111 // Reflection support //////////////////////////////////////////////////////////////////////////////
duke@435 1112
duke@435 1113 JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls))
duke@435 1114 assert (cls != NULL, "illegal class");
duke@435 1115 JVMWrapper("JVM_GetClassName");
duke@435 1116 JvmtiVMObjectAllocEventCollector oam;
duke@435 1117 ResourceMark rm(THREAD);
duke@435 1118 const char* name;
duke@435 1119 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
duke@435 1120 name = type2name(java_lang_Class::primitive_type(JNIHandles::resolve(cls)));
duke@435 1121 } else {
duke@435 1122 // Consider caching interned string in Klass
coleenp@4037 1123 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
duke@435 1124 assert(k->is_klass(), "just checking");
hseigel@4278 1125 name = k->external_name();
duke@435 1126 }
duke@435 1127 oop result = StringTable::intern((char*) name, CHECK_NULL);
duke@435 1128 return (jstring) JNIHandles::make_local(env, result);
duke@435 1129 JVM_END
duke@435 1130
duke@435 1131
duke@435 1132 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
duke@435 1133 JVMWrapper("JVM_GetClassInterfaces");
duke@435 1134 JvmtiVMObjectAllocEventCollector oam;
duke@435 1135 oop mirror = JNIHandles::resolve_non_null(cls);
duke@435 1136
duke@435 1137 // Special handling for primitive objects
duke@435 1138 if (java_lang_Class::is_primitive(mirror)) {
duke@435 1139 // Primitive objects does not have any interfaces
never@1577 1140 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
duke@435 1141 return (jobjectArray) JNIHandles::make_local(env, r);
duke@435 1142 }
duke@435 1143
coleenp@4037 1144 KlassHandle klass(thread, java_lang_Class::as_Klass(mirror));
duke@435 1145 // Figure size of result array
duke@435 1146 int size;
duke@435 1147 if (klass->oop_is_instance()) {
coleenp@4037 1148 size = InstanceKlass::cast(klass())->local_interfaces()->length();
duke@435 1149 } else {
duke@435 1150 assert(klass->oop_is_objArray() || klass->oop_is_typeArray(), "Illegal mirror klass");
duke@435 1151 size = 2;
duke@435 1152 }
duke@435 1153
duke@435 1154 // Allocate result array
never@1577 1155 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), size, CHECK_NULL);
duke@435 1156 objArrayHandle result (THREAD, r);
duke@435 1157 // Fill in result
duke@435 1158 if (klass->oop_is_instance()) {
duke@435 1159 // Regular instance klass, fill in all local interfaces
duke@435 1160 for (int index = 0; index < size; index++) {
coleenp@4037 1161 Klass* k = InstanceKlass::cast(klass())->local_interfaces()->at(index);
hseigel@4278 1162 result->obj_at_put(index, k->java_mirror());
duke@435 1163 }
duke@435 1164 } else {
duke@435 1165 // All arrays implement java.lang.Cloneable and java.io.Serializable
hseigel@4278 1166 result->obj_at_put(0, SystemDictionary::Cloneable_klass()->java_mirror());
hseigel@4278 1167 result->obj_at_put(1, SystemDictionary::Serializable_klass()->java_mirror());
duke@435 1168 }
duke@435 1169 return (jobjectArray) JNIHandles::make_local(env, result());
duke@435 1170 JVM_END
duke@435 1171
duke@435 1172
duke@435 1173 JVM_ENTRY(jobject, JVM_GetClassLoader(JNIEnv *env, jclass cls))
duke@435 1174 JVMWrapper("JVM_GetClassLoader");
duke@435 1175 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
duke@435 1176 return NULL;
duke@435 1177 }
coleenp@4037 1178 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
hseigel@4278 1179 oop loader = k->class_loader();
duke@435 1180 return JNIHandles::make_local(env, loader);
duke@435 1181 JVM_END
duke@435 1182
duke@435 1183
duke@435 1184 JVM_QUICK_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
duke@435 1185 JVMWrapper("JVM_IsInterface");
duke@435 1186 oop mirror = JNIHandles::resolve_non_null(cls);
duke@435 1187 if (java_lang_Class::is_primitive(mirror)) {
duke@435 1188 return JNI_FALSE;
duke@435 1189 }
coleenp@4037 1190 Klass* k = java_lang_Class::as_Klass(mirror);
hseigel@4278 1191 jboolean result = k->is_interface();
hseigel@4278 1192 assert(!result || k->oop_is_instance(),
duke@435 1193 "all interfaces are instance types");
duke@435 1194 // The compiler intrinsic for isInterface tests the
duke@435 1195 // Klass::_access_flags bits in the same way.
duke@435 1196 return result;
duke@435 1197 JVM_END
duke@435 1198
duke@435 1199
duke@435 1200 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
duke@435 1201 JVMWrapper("JVM_GetClassSigners");
duke@435 1202 JvmtiVMObjectAllocEventCollector oam;
duke@435 1203 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
duke@435 1204 // There are no signers for primitive types
duke@435 1205 return NULL;
duke@435 1206 }
duke@435 1207
coleenp@5176 1208 objArrayOop signers = java_lang_Class::signers(JNIHandles::resolve_non_null(cls));
duke@435 1209
duke@435 1210 // If there are no signers set in the class, or if the class
duke@435 1211 // is an array, return NULL.
duke@435 1212 if (signers == NULL) return NULL;
duke@435 1213
duke@435 1214 // copy of the signers array
coleenp@4142 1215 Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
duke@435 1216 objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
duke@435 1217 for (int index = 0; index < signers->length(); index++) {
duke@435 1218 signers_copy->obj_at_put(index, signers->obj_at(index));
duke@435 1219 }
duke@435 1220
duke@435 1221 // return the copy
duke@435 1222 return (jobjectArray) JNIHandles::make_local(env, signers_copy);
duke@435 1223 JVM_END
duke@435 1224
duke@435 1225
duke@435 1226 JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
duke@435 1227 JVMWrapper("JVM_SetClassSigners");
duke@435 1228 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
duke@435 1229 // This call is ignored for primitive types and arrays.
duke@435 1230 // Signers are only set once, ClassLoader.java, and thus shouldn't
duke@435 1231 // be called with an array. Only the bootstrap loader creates arrays.
coleenp@4037 1232 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
hseigel@4278 1233 if (k->oop_is_instance()) {
coleenp@5176 1234 java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers)));
duke@435 1235 }
duke@435 1236 }
duke@435 1237 JVM_END
duke@435 1238
duke@435 1239
duke@435 1240 JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
duke@435 1241 JVMWrapper("JVM_GetProtectionDomain");
duke@435 1242 if (JNIHandles::resolve(cls) == NULL) {
duke@435 1243 THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
duke@435 1244 }
duke@435 1245
duke@435 1246 if (java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
duke@435 1247 // Primitive types does not have a protection domain.
duke@435 1248 return NULL;
duke@435 1249 }
duke@435 1250
coleenp@5176 1251 oop pd = java_lang_Class::protection_domain(JNIHandles::resolve(cls));
coleenp@5176 1252 return (jobject) JNIHandles::make_local(env, pd);
duke@435 1253 JVM_END
duke@435 1254
duke@435 1255
mullan@5242 1256 static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) {
mullan@5242 1257 // If there is a security manager and protection domain, check the access
mullan@5242 1258 // in the protection domain, otherwise it is authorized.
mullan@5242 1259 if (java_lang_System::has_security_manager()) {
mullan@5242 1260
mullan@5242 1261 // For bootstrapping, if pd implies method isn't in the JDK, allow
mullan@5242 1262 // this context to revert to older behavior.
mullan@5242 1263 // In this case the isAuthorized field in AccessControlContext is also not
mullan@5242 1264 // present.
mullan@5242 1265 if (Universe::protection_domain_implies_method() == NULL) {
mullan@5242 1266 return true;
mullan@5242 1267 }
mullan@5242 1268
mullan@5242 1269 // Whitelist certain access control contexts
mullan@5242 1270 if (java_security_AccessControlContext::is_authorized(context)) {
mullan@5242 1271 return true;
mullan@5242 1272 }
mullan@5242 1273
mullan@5242 1274 oop prot = klass->protection_domain();
mullan@5242 1275 if (prot != NULL) {
mullan@5242 1276 // Call pd.implies(new SecurityPermission("createAccessControlContext"))
mullan@5242 1277 // in the new wrapper.
mullan@5242 1278 methodHandle m(THREAD, Universe::protection_domain_implies_method());
mullan@5242 1279 Handle h_prot(THREAD, prot);
mullan@5242 1280 JavaValue result(T_BOOLEAN);
mullan@5242 1281 JavaCallArguments args(h_prot);
mullan@5242 1282 JavaCalls::call(&result, m, &args, CHECK_false);
mullan@5242 1283 return (result.get_jboolean() != 0);
mullan@5242 1284 }
mullan@5242 1285 }
mullan@5242 1286 return true;
mullan@5242 1287 }
mullan@5242 1288
mullan@5242 1289 // Create an AccessControlContext with a protection domain with null codesource
mullan@5242 1290 // and null permissions - which gives no permissions.
mullan@5242 1291 oop create_dummy_access_control_context(TRAPS) {
mullan@5242 1292 InstanceKlass* pd_klass = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass());
robm@8430 1293 Handle obj = pd_klass->allocate_instance_handle(CHECK_NULL);
robm@8430 1294 // Call constructor ProtectionDomain(null, null);
robm@8430 1295 JavaValue result(T_VOID);
robm@8430 1296 JavaCalls::call_special(&result, obj, KlassHandle(THREAD, pd_klass),
robm@8430 1297 vmSymbols::object_initializer_name(),
robm@8430 1298 vmSymbols::codesource_permissioncollection_signature(),
robm@8430 1299 Handle(), Handle(), CHECK_NULL);
mullan@5242 1300
mullan@5242 1301 // new ProtectionDomain[] {pd};
mullan@5242 1302 objArrayOop context = oopFactory::new_objArray(pd_klass, 1, CHECK_NULL);
robm@8430 1303 context->obj_at_put(0, obj());
mullan@5242 1304
mullan@5242 1305 // new AccessControlContext(new ProtectionDomain[] {pd})
mullan@5242 1306 objArrayHandle h_context(THREAD, context);
robm@8430 1307 oop acc = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL);
robm@8430 1308 return acc;
mullan@5242 1309 }
duke@435 1310
duke@435 1311 JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))
duke@435 1312 JVMWrapper("JVM_DoPrivileged");
duke@435 1313
duke@435 1314 if (action == NULL) {
duke@435 1315 THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action");
duke@435 1316 }
duke@435 1317
mullan@5242 1318 // Compute the frame initiating the do privileged operation and setup the privileged stack
mullan@5242 1319 vframeStream vfst(thread);
mullan@5242 1320 vfst.security_get_caller_frame(1);
mullan@5242 1321
mullan@5242 1322 if (vfst.at_end()) {
mullan@5242 1323 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "no caller?");
mullan@5242 1324 }
mullan@5242 1325
mullan@5242 1326 Method* method = vfst.method();
mullan@5242 1327 instanceKlassHandle klass (THREAD, method->method_holder());
mullan@5242 1328
mullan@5242 1329 // Check that action object understands "Object run()"
mullan@5242 1330 Handle h_context;
mullan@5242 1331 if (context != NULL) {
mullan@5242 1332 h_context = Handle(THREAD, JNIHandles::resolve(context));
mullan@5242 1333 bool authorized = is_authorized(h_context, klass, CHECK_NULL);
mullan@5242 1334 if (!authorized) {
mullan@5242 1335 // Create an unprivileged access control object and call it's run function
mullan@5242 1336 // instead.
mullan@5242 1337 oop noprivs = create_dummy_access_control_context(CHECK_NULL);
mullan@5242 1338 h_context = Handle(THREAD, noprivs);
mullan@5242 1339 }
mullan@5242 1340 }
duke@435 1341
duke@435 1342 // Check that action object understands "Object run()"
duke@435 1343 Handle object (THREAD, JNIHandles::resolve(action));
duke@435 1344
duke@435 1345 // get run() method
hseigel@4278 1346 Method* m_oop = object->klass()->uncached_lookup_method(
duke@435 1347 vmSymbols::run_method_name(),
lfoltan@6632 1348 vmSymbols::void_object_signature(),
lfoltan@6632 1349 Klass::normal);
duke@435 1350 methodHandle m (THREAD, m_oop);
coleenp@4037 1351 if (m.is_null() || !m->is_method() || !m()->is_public() || m()->is_static()) {
duke@435 1352 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
duke@435 1353 }
duke@435 1354
mullan@5242 1355 // Stack allocated list of privileged stack elements
mullan@5242 1356 PrivilegedElement pi;
duke@435 1357 if (!vfst.at_end()) {
mullan@5242 1358 pi.initialize(&vfst, h_context(), thread->privileged_stack_top(), CHECK_NULL);
duke@435 1359 thread->set_privileged_stack_top(&pi);
duke@435 1360 }
duke@435 1361
duke@435 1362
duke@435 1363 // invoke the Object run() in the action object. We cannot use call_interface here, since the static type
duke@435 1364 // is not really known - it is either java.security.PrivilegedAction or java.security.PrivilegedExceptionAction
duke@435 1365 Handle pending_exception;
duke@435 1366 JavaValue result(T_OBJECT);
duke@435 1367 JavaCallArguments args(object);
duke@435 1368 JavaCalls::call(&result, m, &args, THREAD);
duke@435 1369
duke@435 1370 // done with action, remove ourselves from the list
duke@435 1371 if (!vfst.at_end()) {
duke@435 1372 assert(thread->privileged_stack_top() != NULL && thread->privileged_stack_top() == &pi, "wrong top element");
duke@435 1373 thread->set_privileged_stack_top(thread->privileged_stack_top()->next());
duke@435 1374 }
duke@435 1375
duke@435 1376 if (HAS_PENDING_EXCEPTION) {
duke@435 1377 pending_exception = Handle(THREAD, PENDING_EXCEPTION);
duke@435 1378 CLEAR_PENDING_EXCEPTION;
jbachorik@7812 1379 // JVMTI has already reported the pending exception
jbachorik@7812 1380 // JVMTI internal flag reset is needed in order to report PrivilegedActionException
jbachorik@7812 1381 if (THREAD->is_Java_thread()) {
jbachorik@7812 1382 JvmtiExport::clear_detected_exception((JavaThread*) THREAD);
jbachorik@7812 1383 }
never@1577 1384 if ( pending_exception->is_a(SystemDictionary::Exception_klass()) &&
never@1577 1385 !pending_exception->is_a(SystemDictionary::RuntimeException_klass())) {
duke@435 1386 // Throw a java.security.PrivilegedActionException(Exception e) exception
duke@435 1387 JavaCallArguments args(pending_exception);
coleenp@2497 1388 THROW_ARG_0(vmSymbols::java_security_PrivilegedActionException(),
coleenp@2497 1389 vmSymbols::exception_void_signature(),
duke@435 1390 &args);
duke@435 1391 }
duke@435 1392 }
duke@435 1393
duke@435 1394 if (pending_exception.not_null()) THROW_OOP_0(pending_exception());
duke@435 1395 return JNIHandles::make_local(env, (oop) result.get_jobject());
duke@435 1396 JVM_END
duke@435 1397
duke@435 1398
duke@435 1399 // Returns the inherited_access_control_context field of the running thread.
duke@435 1400 JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls))
duke@435 1401 JVMWrapper("JVM_GetInheritedAccessControlContext");
duke@435 1402 oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj());
duke@435 1403 return JNIHandles::make_local(env, result);
duke@435 1404 JVM_END
duke@435 1405
duke@435 1406 class RegisterArrayForGC {
duke@435 1407 private:
duke@435 1408 JavaThread *_thread;
duke@435 1409 public:
duke@435 1410 RegisterArrayForGC(JavaThread *thread, GrowableArray<oop>* array) {
duke@435 1411 _thread = thread;
duke@435 1412 _thread->register_array_for_gc(array);
duke@435 1413 }
duke@435 1414
duke@435 1415 ~RegisterArrayForGC() {
duke@435 1416 _thread->register_array_for_gc(NULL);
duke@435 1417 }
duke@435 1418 };
duke@435 1419
duke@435 1420
duke@435 1421 JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
duke@435 1422 JVMWrapper("JVM_GetStackAccessControlContext");
duke@435 1423 if (!UsePrivilegedStack) return NULL;
duke@435 1424
duke@435 1425 ResourceMark rm(THREAD);
duke@435 1426 GrowableArray<oop>* local_array = new GrowableArray<oop>(12);
duke@435 1427 JvmtiVMObjectAllocEventCollector oam;
duke@435 1428
duke@435 1429 // count the protection domains on the execution stack. We collapse
duke@435 1430 // duplicate consecutive protection domains into a single one, as
duke@435 1431 // well as stopping when we hit a privileged frame.
duke@435 1432
duke@435 1433 // Use vframeStream to iterate through Java frames
duke@435 1434 vframeStream vfst(thread);
duke@435 1435
duke@435 1436 oop previous_protection_domain = NULL;
duke@435 1437 Handle privileged_context(thread, NULL);
duke@435 1438 bool is_privileged = false;
duke@435 1439 oop protection_domain = NULL;
duke@435 1440
duke@435 1441 for(; !vfst.at_end(); vfst.next()) {
duke@435 1442 // get method of frame
coleenp@4037 1443 Method* method = vfst.method();
duke@435 1444 intptr_t* frame_id = vfst.frame_id();
duke@435 1445
duke@435 1446 // check the privileged frames to see if we have a match
duke@435 1447 if (thread->privileged_stack_top() && thread->privileged_stack_top()->frame_id() == frame_id) {
duke@435 1448 // this frame is privileged
duke@435 1449 is_privileged = true;
duke@435 1450 privileged_context = Handle(thread, thread->privileged_stack_top()->privileged_context());
duke@435 1451 protection_domain = thread->privileged_stack_top()->protection_domain();
duke@435 1452 } else {
coleenp@4251 1453 protection_domain = method->method_holder()->protection_domain();
duke@435 1454 }
duke@435 1455
duke@435 1456 if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
duke@435 1457 local_array->push(protection_domain);
duke@435 1458 previous_protection_domain = protection_domain;
duke@435 1459 }
duke@435 1460
duke@435 1461 if (is_privileged) break;
duke@435 1462 }
duke@435 1463
duke@435 1464
duke@435 1465 // either all the domains on the stack were system domains, or
duke@435 1466 // we had a privileged system domain
duke@435 1467 if (local_array->is_empty()) {
duke@435 1468 if (is_privileged && privileged_context.is_null()) return NULL;
duke@435 1469
duke@435 1470 oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
duke@435 1471 return JNIHandles::make_local(env, result);
duke@435 1472 }
duke@435 1473
duke@435 1474 // the resource area must be registered in case of a gc
duke@435 1475 RegisterArrayForGC ragc(thread, local_array);
never@1577 1476 objArrayOop context = oopFactory::new_objArray(SystemDictionary::ProtectionDomain_klass(),
duke@435 1477 local_array->length(), CHECK_NULL);
duke@435 1478 objArrayHandle h_context(thread, context);
duke@435 1479 for (int index = 0; index < local_array->length(); index++) {
duke@435 1480 h_context->obj_at_put(index, local_array->at(index));
duke@435 1481 }
duke@435 1482
duke@435 1483 oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
duke@435 1484
duke@435 1485 return JNIHandles::make_local(env, result);
duke@435 1486 JVM_END
duke@435 1487
duke@435 1488
duke@435 1489 JVM_QUICK_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
duke@435 1490 JVMWrapper("JVM_IsArrayClass");
coleenp@4037 1491 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
hseigel@4278 1492 return (k != NULL) && k->oop_is_array() ? true : false;
duke@435 1493 JVM_END
duke@435 1494
duke@435 1495
duke@435 1496 JVM_QUICK_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
duke@435 1497 JVMWrapper("JVM_IsPrimitiveClass");
duke@435 1498 oop mirror = JNIHandles::resolve_non_null(cls);
duke@435 1499 return (jboolean) java_lang_Class::is_primitive(mirror);
duke@435 1500 JVM_END
duke@435 1501
duke@435 1502
duke@435 1503 JVM_ENTRY(jclass, JVM_GetComponentType(JNIEnv *env, jclass cls))
duke@435 1504 JVMWrapper("JVM_GetComponentType");
duke@435 1505 oop mirror = JNIHandles::resolve_non_null(cls);
duke@435 1506 oop result = Reflection::array_component_type(mirror, CHECK_NULL);
duke@435 1507 return (jclass) JNIHandles::make_local(env, result);
duke@435 1508 JVM_END
duke@435 1509
duke@435 1510
duke@435 1511 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
duke@435 1512 JVMWrapper("JVM_GetClassModifiers");
duke@435 1513 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
duke@435 1514 // Primitive type
duke@435 1515 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@435 1516 }
duke@435 1517
hseigel@4278 1518 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 1519 debug_only(int computed_modifiers = k->compute_modifier_flags(CHECK_0));
duke@435 1520 assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK");
duke@435 1521 return k->modifier_flags();
duke@435 1522 JVM_END
duke@435 1523
duke@435 1524
duke@435 1525 // Inner class reflection ///////////////////////////////////////////////////////////////////////////////
duke@435 1526
duke@435 1527 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
duke@435 1528 JvmtiVMObjectAllocEventCollector oam;
duke@435 1529 // ofClass is a reference to a java_lang_Class object. The mirror object
coleenp@4037 1530 // of an InstanceKlass
duke@435 1531
duke@435 1532 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
hseigel@4278 1533 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) {
never@1577 1534 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
duke@435 1535 return (jobjectArray)JNIHandles::make_local(env, result);
duke@435 1536 }
duke@435 1537
coleenp@4037 1538 instanceKlassHandle k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
jiangli@3670 1539 InnerClassesIterator iter(k);
jiangli@3670 1540
jiangli@3670 1541 if (iter.length() == 0) {
duke@435 1542 // Neither an inner nor outer class
never@1577 1543 oop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_NULL);
duke@435 1544 return (jobjectArray)JNIHandles::make_local(env, result);
duke@435 1545 }
duke@435 1546
duke@435 1547 // find inner class info
duke@435 1548 constantPoolHandle cp(thread, k->constants());
jiangli@3670 1549 int length = iter.length();
duke@435 1550
duke@435 1551 // Allocate temp. result array
never@1577 1552 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length/4, CHECK_NULL);
duke@435 1553 objArrayHandle result (THREAD, r);
duke@435 1554 int members = 0;
duke@435 1555
jiangli@3670 1556 for (; !iter.done(); iter.next()) {
jiangli@3670 1557 int ioff = iter.inner_class_info_index();
jiangli@3670 1558 int ooff = iter.outer_class_info_index();
duke@435 1559
duke@435 1560 if (ioff != 0 && ooff != 0) {
duke@435 1561 // Check to see if the name matches the class we're looking for
duke@435 1562 // before attempting to find the class.
duke@435 1563 if (cp->klass_name_at_matches(k, ooff)) {
coleenp@4037 1564 Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
duke@435 1565 if (outer_klass == k()) {
coleenp@4037 1566 Klass* ik = cp->klass_at(ioff, CHECK_NULL);
duke@435 1567 instanceKlassHandle inner_klass (THREAD, ik);
duke@435 1568
duke@435 1569 // Throws an exception if outer klass has not declared k as
duke@435 1570 // an inner klass
jrose@1100 1571 Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
duke@435 1572
duke@435 1573 result->obj_at_put(members, inner_klass->java_mirror());
duke@435 1574 members++;
duke@435 1575 }
duke@435 1576 }
duke@435 1577 }
duke@435 1578 }
duke@435 1579
duke@435 1580 if (members != length) {
duke@435 1581 // Return array of right length
never@1577 1582 objArrayOop res = oopFactory::new_objArray(SystemDictionary::Class_klass(), members, CHECK_NULL);
duke@435 1583 for(int i = 0; i < members; i++) {
duke@435 1584 res->obj_at_put(i, result->obj_at(i));
duke@435 1585 }
duke@435 1586 return (jobjectArray)JNIHandles::make_local(env, res);
duke@435 1587 }
duke@435 1588
duke@435 1589 return (jobjectArray)JNIHandles::make_local(env, result());
duke@435 1590 JVM_END
duke@435 1591
duke@435 1592
duke@435 1593 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
jrose@1100 1594 {
duke@435 1595 // ofClass is a reference to a java_lang_Class object.
duke@435 1596 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
hseigel@4278 1597 ! java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_instance()) {
duke@435 1598 return NULL;
duke@435 1599 }
duke@435 1600
xlu@1561 1601 bool inner_is_member = false;
coleenp@4037 1602 Klass* outer_klass
coleenp@4037 1603 = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))
xlu@1561 1604 )->compute_enclosing_class(&inner_is_member, CHECK_NULL);
jrose@1100 1605 if (outer_klass == NULL) return NULL; // already a top-level class
xlu@1561 1606 if (!inner_is_member) return NULL; // an anonymous class (inside a method)
hseigel@4278 1607 return (jclass) JNIHandles::make_local(env, outer_klass->java_mirror());
jrose@1100 1608 }
jrose@1100 1609 JVM_END
jrose@1100 1610
coleenp@4037 1611 // should be in InstanceKlass.cpp, but is here for historical reasons
coleenp@4037 1612 Klass* InstanceKlass::compute_enclosing_class_impl(instanceKlassHandle k,
xlu@1561 1613 bool* inner_is_member,
xlu@1561 1614 TRAPS) {
jrose@1100 1615 Thread* thread = THREAD;
jiangli@3670 1616 InnerClassesIterator iter(k);
jiangli@3670 1617 if (iter.length() == 0) {
duke@435 1618 // No inner class info => no declaring class
duke@435 1619 return NULL;
duke@435 1620 }
duke@435 1621
duke@435 1622 constantPoolHandle i_cp(thread, k->constants());
duke@435 1623
duke@435 1624 bool found = false;
coleenp@4037 1625 Klass* ok;
duke@435 1626 instanceKlassHandle outer_klass;
xlu@1561 1627 *inner_is_member = false;
duke@435 1628
duke@435 1629 // Find inner_klass attribute
jiangli@3670 1630 for (; !iter.done() && !found; iter.next()) {
jiangli@3670 1631 int ioff = iter.inner_class_info_index();
jiangli@3670 1632 int ooff = iter.outer_class_info_index();
jiangli@3670 1633 int noff = iter.inner_name_index();
jrose@1100 1634 if (ioff != 0) {
duke@435 1635 // Check to see if the name matches the class we're looking for
duke@435 1636 // before attempting to find the class.
duke@435 1637 if (i_cp->klass_name_at_matches(k, ioff)) {
coleenp@4037 1638 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_NULL);
jrose@1100 1639 found = (k() == inner_klass);
jrose@1100 1640 if (found && ooff != 0) {
duke@435 1641 ok = i_cp->klass_at(ooff, CHECK_NULL);
duke@435 1642 outer_klass = instanceKlassHandle(thread, ok);
xlu@1561 1643 *inner_is_member = true;
duke@435 1644 }
duke@435 1645 }
duke@435 1646 }
duke@435 1647 }
duke@435 1648
jrose@1100 1649 if (found && outer_klass.is_null()) {
jrose@1100 1650 // It may be anonymous; try for that.
jrose@1100 1651 int encl_method_class_idx = k->enclosing_method_class_index();
jrose@1100 1652 if (encl_method_class_idx != 0) {
jrose@1100 1653 ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
jrose@1100 1654 outer_klass = instanceKlassHandle(thread, ok);
xlu@1561 1655 *inner_is_member = false;
jrose@1100 1656 }
jrose@1100 1657 }
jrose@1100 1658
duke@435 1659 // If no inner class attribute found for this class.
jrose@1100 1660 if (outer_klass.is_null()) return NULL;
duke@435 1661
duke@435 1662 // Throws an exception if outer klass has not declared k as an inner klass
jrose@1100 1663 // We need evidence that each klass knows about the other, or else
jrose@1100 1664 // the system could allow a spoof of an inner class to gain access rights.
xlu@1561 1665 Reflection::check_for_inner_class(outer_klass, k, *inner_is_member, CHECK_NULL);
jrose@1100 1666 return outer_klass();
jrose@1100 1667 }
duke@435 1668
duke@435 1669 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
duke@435 1670 assert (cls != NULL, "illegal class");
duke@435 1671 JVMWrapper("JVM_GetClassSignature");
duke@435 1672 JvmtiVMObjectAllocEventCollector oam;
duke@435 1673 ResourceMark rm(THREAD);
duke@435 1674 // Return null for arrays and primatives
duke@435 1675 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
coleenp@4037 1676 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
hseigel@4278 1677 if (k->oop_is_instance()) {
coleenp@4037 1678 Symbol* sym = InstanceKlass::cast(k)->generic_signature();
coleenp@2497 1679 if (sym == NULL) return NULL;
duke@435 1680 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
duke@435 1681 return (jstring) JNIHandles::make_local(env, str());
duke@435 1682 }
duke@435 1683 }
duke@435 1684 return NULL;
duke@435 1685 JVM_END
duke@435 1686
duke@435 1687
duke@435 1688 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
duke@435 1689 assert (cls != NULL, "illegal class");
duke@435 1690 JVMWrapper("JVM_GetClassAnnotations");
rbackman@4818 1691
duke@435 1692 // Return null for arrays and primitives
duke@435 1693 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
coleenp@4037 1694 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
hseigel@4278 1695 if (k->oop_is_instance()) {
coleenp@4037 1696 typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL);
coleenp@4037 1697 return (jbyteArray) JNIHandles::make_local(env, a);
duke@435 1698 }
duke@435 1699 }
duke@435 1700 return NULL;
duke@435 1701 JVM_END
duke@435 1702
duke@435 1703
rbackman@4818 1704 static bool jvm_get_field_common(jobject field, fieldDescriptor& fd, TRAPS) {
duke@435 1705 // some of this code was adapted from from jni_FromReflectedField
duke@435 1706
duke@435 1707 oop reflected = JNIHandles::resolve_non_null(field);
duke@435 1708 oop mirror = java_lang_reflect_Field::clazz(reflected);
coleenp@4037 1709 Klass* k = java_lang_Class::as_Klass(mirror);
duke@435 1710 int slot = java_lang_reflect_Field::slot(reflected);
duke@435 1711 int modifiers = java_lang_reflect_Field::modifiers(reflected);
duke@435 1712
duke@435 1713 KlassHandle kh(THREAD, k);
coleenp@4037 1714 intptr_t offset = InstanceKlass::cast(kh())->field_offset(slot);
duke@435 1715
duke@435 1716 if (modifiers & JVM_ACC_STATIC) {
duke@435 1717 // for static fields we only look in the current class
coleenp@4037 1718 if (!InstanceKlass::cast(kh())->find_local_field_from_offset(offset, true, &fd)) {
duke@435 1719 assert(false, "cannot find static field");
rbackman@4818 1720 return false;
duke@435 1721 }
duke@435 1722 } else {
duke@435 1723 // for instance fields we start with the current class and work
duke@435 1724 // our way up through the superclass chain
coleenp@4037 1725 if (!InstanceKlass::cast(kh())->find_field_from_offset(offset, false, &fd)) {
duke@435 1726 assert(false, "cannot find instance field");
rbackman@4818 1727 return false;
duke@435 1728 }
duke@435 1729 }
rbackman@4818 1730 return true;
rbackman@4818 1731 }
rbackman@4818 1732
rbackman@4818 1733 JVM_ENTRY(jbyteArray, JVM_GetFieldAnnotations(JNIEnv *env, jobject field))
rbackman@4818 1734 // field is a handle to a java.lang.reflect.Field object
rbackman@4818 1735 assert(field != NULL, "illegal field");
rbackman@4818 1736 JVMWrapper("JVM_GetFieldAnnotations");
rbackman@4818 1737
rbackman@4818 1738 fieldDescriptor fd;
rbackman@4818 1739 bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
rbackman@4818 1740 if (!gotFd) {
rbackman@4818 1741 return NULL;
rbackman@4818 1742 }
duke@435 1743
coleenp@4037 1744 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD));
duke@435 1745 JVM_END
duke@435 1746
duke@435 1747
coleenp@4398 1748 static Method* jvm_get_method_common(jobject method) {
duke@435 1749 // some of this code was adapted from from jni_FromReflectedMethod
duke@435 1750
duke@435 1751 oop reflected = JNIHandles::resolve_non_null(method);
duke@435 1752 oop mirror = NULL;
duke@435 1753 int slot = 0;
duke@435 1754
never@1577 1755 if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) {
duke@435 1756 mirror = java_lang_reflect_Constructor::clazz(reflected);
duke@435 1757 slot = java_lang_reflect_Constructor::slot(reflected);
duke@435 1758 } else {
never@1577 1759 assert(reflected->klass() == SystemDictionary::reflect_Method_klass(),
duke@435 1760 "wrong type");
duke@435 1761 mirror = java_lang_reflect_Method::clazz(reflected);
duke@435 1762 slot = java_lang_reflect_Method::slot(reflected);
duke@435 1763 }
coleenp@4037 1764 Klass* k = java_lang_Class::as_Klass(mirror);
duke@435 1765
coleenp@4398 1766 Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
rbackman@4818 1767 assert(m != NULL, "cannot find method");
rbackman@4818 1768 return m; // caller has to deal with NULL in product mode
duke@435 1769 }
duke@435 1770
duke@435 1771
duke@435 1772 JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
duke@435 1773 JVMWrapper("JVM_GetMethodAnnotations");
duke@435 1774
duke@435 1775 // method is a handle to a java.lang.reflect.Method object
coleenp@4398 1776 Method* m = jvm_get_method_common(method);
rbackman@4818 1777 if (m == NULL) {
rbackman@4818 1778 return NULL;
rbackman@4818 1779 }
rbackman@4818 1780
coleenp@4037 1781 return (jbyteArray) JNIHandles::make_local(env,
coleenp@4037 1782 Annotations::make_java_array(m->annotations(), THREAD));
duke@435 1783 JVM_END
duke@435 1784
duke@435 1785
duke@435 1786 JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
duke@435 1787 JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
duke@435 1788
duke@435 1789 // method is a handle to a java.lang.reflect.Method object
coleenp@4398 1790 Method* m = jvm_get_method_common(method);
rbackman@4818 1791 if (m == NULL) {
rbackman@4818 1792 return NULL;
rbackman@4818 1793 }
rbackman@4818 1794
coleenp@4037 1795 return (jbyteArray) JNIHandles::make_local(env,
coleenp@4037 1796 Annotations::make_java_array(m->annotation_default(), THREAD));
duke@435 1797 JVM_END
duke@435 1798
duke@435 1799
duke@435 1800 JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
duke@435 1801 JVMWrapper("JVM_GetMethodParameterAnnotations");
duke@435 1802
duke@435 1803 // method is a handle to a java.lang.reflect.Method object
coleenp@4398 1804 Method* m = jvm_get_method_common(method);
rbackman@4818 1805 if (m == NULL) {
rbackman@4818 1806 return NULL;
rbackman@4818 1807 }
rbackman@4818 1808
coleenp@4037 1809 return (jbyteArray) JNIHandles::make_local(env,
coleenp@4037 1810 Annotations::make_java_array(m->parameter_annotations(), THREAD));
duke@435 1811 JVM_END
duke@435 1812
stefank@4393 1813 /* Type use annotations support (JDK 1.8) */
stefank@4393 1814
stefank@4393 1815 JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls))
stefank@4393 1816 assert (cls != NULL, "illegal class");
stefank@4393 1817 JVMWrapper("JVM_GetClassTypeAnnotations");
stefank@4393 1818 ResourceMark rm(THREAD);
stefank@4393 1819 // Return null for arrays and primitives
stefank@4393 1820 if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
stefank@4393 1821 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
stefank@4393 1822 if (k->oop_is_instance()) {
coleenp@4572 1823 AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations();
stefank@4454 1824 if (type_annotations != NULL) {
coleenp@4572 1825 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
stefank@4454 1826 return (jbyteArray) JNIHandles::make_local(env, a);
stefank@4454 1827 }
stefank@4393 1828 }
stefank@4393 1829 }
stefank@4393 1830 return NULL;
stefank@4393 1831 JVM_END
stefank@4393 1832
rbackman@4818 1833 JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method))
rbackman@4818 1834 assert (method != NULL, "illegal method");
rbackman@4818 1835 JVMWrapper("JVM_GetMethodTypeAnnotations");
rbackman@4818 1836
rbackman@4818 1837 // method is a handle to a java.lang.reflect.Method object
rbackman@4818 1838 Method* m = jvm_get_method_common(method);
rbackman@4818 1839 if (m == NULL) {
rbackman@4818 1840 return NULL;
rbackman@4818 1841 }
rbackman@4818 1842
rbackman@4818 1843 AnnotationArray* type_annotations = m->type_annotations();
rbackman@4818 1844 if (type_annotations != NULL) {
rbackman@4818 1845 typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
rbackman@4818 1846 return (jbyteArray) JNIHandles::make_local(env, a);
rbackman@4818 1847 }
rbackman@4818 1848
rbackman@4818 1849 return NULL;
rbackman@4818 1850 JVM_END
rbackman@4818 1851
rbackman@4818 1852 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
rbackman@4818 1853 assert (field != NULL, "illegal field");
rbackman@4818 1854 JVMWrapper("JVM_GetFieldTypeAnnotations");
rbackman@4818 1855
rbackman@4818 1856 fieldDescriptor fd;
rbackman@4818 1857 bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
rbackman@4818 1858 if (!gotFd) {
rbackman@4818 1859 return NULL;
rbackman@4818 1860 }
rbackman@4818 1861
rbackman@4818 1862 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
rbackman@4818 1863 JVM_END
rbackman@4818 1864
coleenp@4431 1865 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
coleenp@4431 1866 if (!cp->is_within_bounds(index)) {
coleenp@4431 1867 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
coleenp@4431 1868 }
coleenp@4431 1869 }
coleenp@4431 1870
coleenp@4398 1871 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
coleenp@4398 1872 {
coleenp@4398 1873 JVMWrapper("JVM_GetMethodParameters");
coleenp@4398 1874 // method is a handle to a java.lang.reflect.Method object
coleenp@4398 1875 Method* method_ptr = jvm_get_method_common(method);
coleenp@4398 1876 methodHandle mh (THREAD, method_ptr);
coleenp@4398 1877 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
coleenp@4398 1878 const int num_params = mh->method_parameters_length();
coleenp@4398 1879
coleenp@4431 1880 if (0 != num_params) {
coleenp@4431 1881 // make sure all the symbols are properly formatted
coleenp@4431 1882 for (int i = 0; i < num_params; i++) {
coleenp@4431 1883 MethodParametersElement* params = mh->method_parameters_start();
coleenp@4431 1884 int index = params[i].name_cp_index;
coleenp@4431 1885 bounds_check(mh->constants(), index, CHECK_NULL);
coleenp@4431 1886
coleenp@4431 1887 if (0 != index && !mh->constants()->tag_at(index).is_utf8()) {
coleenp@4431 1888 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
coleenp@4431 1889 "Wrong type at constant pool index");
coleenp@4431 1890 }
coleenp@4431 1891
coleenp@4431 1892 }
coleenp@4431 1893
coleenp@4398 1894 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL);
coleenp@4398 1895 objArrayHandle result (THREAD, result_oop);
coleenp@4398 1896
coleenp@4431 1897 for (int i = 0; i < num_params; i++) {
coleenp@4398 1898 MethodParametersElement* params = mh->method_parameters_start();
coleenp@4431 1899 // For a 0 index, give a NULL symbol
minqi@5097 1900 Symbol* sym = 0 != params[i].name_cp_index ?
coleenp@4431 1901 mh->constants()->symbol_at(params[i].name_cp_index) : NULL;
emc@4524 1902 int flags = params[i].flags;
coleenp@4398 1903 oop param = Reflection::new_parameter(reflected_method, i, sym,
coleenp@4431 1904 flags, CHECK_NULL);
coleenp@4398 1905 result->obj_at_put(i, param);
coleenp@4398 1906 }
coleenp@4398 1907 return (jobjectArray)JNIHandles::make_local(env, result());
coleenp@4398 1908 } else {
coleenp@4398 1909 return (jobjectArray)NULL;
coleenp@4398 1910 }
coleenp@4398 1911 }
coleenp@4398 1912 JVM_END
duke@435 1913
duke@435 1914 // New (JDK 1.4) reflection implementation /////////////////////////////////////
duke@435 1915
duke@435 1916 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
duke@435 1917 {
duke@435 1918 JVMWrapper("JVM_GetClassDeclaredFields");
duke@435 1919 JvmtiVMObjectAllocEventCollector oam;
duke@435 1920
duke@435 1921 // Exclude primitive types and array types
duke@435 1922 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
hseigel@4278 1923 java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
duke@435 1924 // Return empty array
never@1577 1925 oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
duke@435 1926 return (jobjectArray) JNIHandles::make_local(env, res);
duke@435 1927 }
duke@435 1928
coleenp@4037 1929 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
duke@435 1930 constantPoolHandle cp(THREAD, k->constants());
duke@435 1931
duke@435 1932 // Ensure class is linked
duke@435 1933 k->link_class(CHECK_NULL);
duke@435 1934
duke@435 1935 // 4496456 We need to filter out java.lang.Throwable.backtrace
duke@435 1936 bool skip_backtrace = false;
duke@435 1937
duke@435 1938 // Allocate result
duke@435 1939 int num_fields;
duke@435 1940
duke@435 1941 if (publicOnly) {
duke@435 1942 num_fields = 0;
never@3137 1943 for (JavaFieldStream fs(k()); !fs.done(); fs.next()) {
never@3137 1944 if (fs.access_flags().is_public()) ++num_fields;
duke@435 1945 }
duke@435 1946 } else {
never@3137 1947 num_fields = k->java_fields_count();
duke@435 1948
never@1577 1949 if (k() == SystemDictionary::Throwable_klass()) {
duke@435 1950 num_fields--;
duke@435 1951 skip_backtrace = true;
duke@435 1952 }
duke@435 1953 }
duke@435 1954
never@1577 1955 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
duke@435 1956 objArrayHandle result (THREAD, r);
duke@435 1957
duke@435 1958 int out_idx = 0;
duke@435 1959 fieldDescriptor fd;
never@3137 1960 for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
duke@435 1961 if (skip_backtrace) {
duke@435 1962 // 4496456 skip java.lang.Throwable.backtrace
never@3137 1963 int offset = fs.offset();
duke@435 1964 if (offset == java_lang_Throwable::get_backtrace_offset()) continue;
duke@435 1965 }
duke@435 1966
never@3137 1967 if (!publicOnly || fs.access_flags().is_public()) {
drchase@5732 1968 fd.reinitialize(k(), fs.index());
duke@435 1969 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
duke@435 1970 result->obj_at_put(out_idx, field);
duke@435 1971 ++out_idx;
duke@435 1972 }
duke@435 1973 }
duke@435 1974 assert(out_idx == num_fields, "just checking");
duke@435 1975 return (jobjectArray) JNIHandles::make_local(env, result());
duke@435 1976 }
duke@435 1977 JVM_END
duke@435 1978
coleenp@5749 1979 static bool select_method(methodHandle method, bool want_constructor) {
coleenp@5749 1980 if (want_constructor) {
coleenp@5749 1981 return (method->is_initializer() && !method->is_static());
coleenp@5749 1982 } else {
coleenp@5749 1983 return (!method->is_initializer() && !method->is_overpass());
coleenp@5749 1984 }
coleenp@5749 1985 }
coleenp@5749 1986
coleenp@5749 1987 static jobjectArray get_class_declared_methods_helper(
coleenp@5749 1988 JNIEnv *env,
coleenp@5749 1989 jclass ofClass, jboolean publicOnly,
coleenp@5749 1990 bool want_constructor,
coleenp@5749 1991 Klass* klass, TRAPS) {
coleenp@5749 1992
duke@435 1993 JvmtiVMObjectAllocEventCollector oam;
duke@435 1994
duke@435 1995 // Exclude primitive types and array types
duke@435 1996 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
hseigel@4278 1997 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
duke@435 1998 // Return empty array
coleenp@5749 1999 oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
duke@435 2000 return (jobjectArray) JNIHandles::make_local(env, res);
duke@435 2001 }
duke@435 2002
coleenp@4037 2003 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
duke@435 2004
duke@435 2005 // Ensure class is linked
duke@435 2006 k->link_class(CHECK_NULL);
duke@435 2007
coleenp@4037 2008 Array<Method*>* methods = k->methods();
duke@435 2009 int methods_length = methods->length();
coleenp@5749 2010
coleenp@5749 2011 // Save original method_idnum in case of redefinition, which can change
coleenp@5749 2012 // the idnum of obsolete methods. The new method will have the same idnum
coleenp@5749 2013 // but if we refresh the methods array, the counts will be wrong.
coleenp@5749 2014 ResourceMark rm(THREAD);
coleenp@5749 2015 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
duke@435 2016 int num_methods = 0;
duke@435 2017
coleenp@5749 2018 for (int i = 0; i < methods_length; i++) {
coleenp@4037 2019 methodHandle method(THREAD, methods->at(i));
coleenp@5749 2020 if (select_method(method, want_constructor)) {
duke@435 2021 if (!publicOnly || method->is_public()) {
coleenp@5749 2022 idnums->push(method->method_idnum());
duke@435 2023 ++num_methods;
duke@435 2024 }
duke@435 2025 }
duke@435 2026 }
duke@435 2027
duke@435 2028 // Allocate result
coleenp@5749 2029 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
duke@435 2030 objArrayHandle result (THREAD, r);
duke@435 2031
coleenp@5749 2032 // Now just put the methods that we selected above, but go by their idnum
coleenp@5749 2033 // in case of redefinition. The methods can be redefined at any safepoint,
coleenp@5749 2034 // so above when allocating the oop array and below when creating reflect
coleenp@5749 2035 // objects.
coleenp@5749 2036 for (int i = 0; i < num_methods; i++) {
coleenp@5749 2037 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
coleenp@5749 2038 if (method.is_null()) {
coleenp@5749 2039 // Method may have been deleted and seems this API can handle null
coleenp@5749 2040 // Otherwise should probably put a method that throws NSME
coleenp@5749 2041 result->obj_at_put(i, NULL);
coleenp@5749 2042 } else {
coleenp@5749 2043 oop m;
coleenp@5749 2044 if (want_constructor) {
coleenp@5749 2045 m = Reflection::new_constructor(method, CHECK_NULL);
coleenp@5749 2046 } else {
coleenp@5749 2047 m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
duke@435 2048 }
coleenp@5749 2049 result->obj_at_put(i, m);
duke@435 2050 }
duke@435 2051 }
coleenp@5749 2052
duke@435 2053 return (jobjectArray) JNIHandles::make_local(env, result());
duke@435 2054 }
coleenp@5749 2055
coleenp@5749 2056 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
coleenp@5749 2057 {
coleenp@5749 2058 JVMWrapper("JVM_GetClassDeclaredMethods");
coleenp@5749 2059 return get_class_declared_methods_helper(env, ofClass, publicOnly,
coleenp@5749 2060 /*want_constructor*/ false,
coleenp@5749 2061 SystemDictionary::reflect_Method_klass(), THREAD);
coleenp@5749 2062 }
duke@435 2063 JVM_END
duke@435 2064
duke@435 2065 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
duke@435 2066 {
duke@435 2067 JVMWrapper("JVM_GetClassDeclaredConstructors");
coleenp@5749 2068 return get_class_declared_methods_helper(env, ofClass, publicOnly,
coleenp@5749 2069 /*want_constructor*/ true,
coleenp@5749 2070 SystemDictionary::reflect_Constructor_klass(), THREAD);
duke@435 2071 }
duke@435 2072 JVM_END
duke@435 2073
duke@435 2074 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
duke@435 2075 {
duke@435 2076 JVMWrapper("JVM_GetClassAccessFlags");
duke@435 2077 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
duke@435 2078 // Primitive type
duke@435 2079 return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
duke@435 2080 }
duke@435 2081
hseigel@4278 2082 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2083 return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS;
duke@435 2084 }
duke@435 2085 JVM_END
duke@435 2086
duke@435 2087
duke@435 2088 // Constant pool access //////////////////////////////////////////////////////////
duke@435 2089
duke@435 2090 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
duke@435 2091 {
duke@435 2092 JVMWrapper("JVM_GetClassConstantPool");
duke@435 2093 JvmtiVMObjectAllocEventCollector oam;
duke@435 2094
duke@435 2095 // Return null for primitives and arrays
duke@435 2096 if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
coleenp@4037 2097 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
hseigel@4278 2098 if (k->oop_is_instance()) {
duke@435 2099 instanceKlassHandle k_h(THREAD, k);
duke@435 2100 Handle jcp = sun_reflect_ConstantPool::create(CHECK_NULL);
coleenp@4037 2101 sun_reflect_ConstantPool::set_cp(jcp(), k_h->constants());
duke@435 2102 return JNIHandles::make_local(jcp());
duke@435 2103 }
duke@435 2104 }
duke@435 2105 return NULL;
duke@435 2106 }
duke@435 2107 JVM_END
duke@435 2108
duke@435 2109
coleenp@4037 2110 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused))
duke@435 2111 {
duke@435 2112 JVMWrapper("JVM_ConstantPoolGetSize");
coleenp@4037 2113 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2114 return cp->length();
duke@435 2115 }
duke@435 2116 JVM_END
duke@435 2117
duke@435 2118
coleenp@4037 2119 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2120 {
duke@435 2121 JVMWrapper("JVM_ConstantPoolGetClassAt");
coleenp@4037 2122 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2123 bounds_check(cp, index, CHECK_NULL);
duke@435 2124 constantTag tag = cp->tag_at(index);
duke@435 2125 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
duke@435 2126 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2127 }
coleenp@4037 2128 Klass* k = cp->klass_at(index, CHECK_NULL);
never@2658 2129 return (jclass) JNIHandles::make_local(k->java_mirror());
duke@435 2130 }
duke@435 2131 JVM_END
duke@435 2132
coleenp@4037 2133 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2134 {
duke@435 2135 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
coleenp@4037 2136 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2137 bounds_check(cp, index, CHECK_NULL);
duke@435 2138 constantTag tag = cp->tag_at(index);
duke@435 2139 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
duke@435 2140 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2141 }
coleenp@4037 2142 Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
duke@435 2143 if (k == NULL) return NULL;
never@2658 2144 return (jclass) JNIHandles::make_local(k->java_mirror());
duke@435 2145 }
duke@435 2146 JVM_END
duke@435 2147
duke@435 2148 static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
duke@435 2149 constantTag tag = cp->tag_at(index);
duke@435 2150 if (!tag.is_method() && !tag.is_interface_method()) {
duke@435 2151 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2152 }
duke@435 2153 int klass_ref = cp->uncached_klass_ref_index_at(index);
coleenp@4037 2154 Klass* k_o;
duke@435 2155 if (force_resolution) {
duke@435 2156 k_o = cp->klass_at(klass_ref, CHECK_NULL);
duke@435 2157 } else {
coleenp@4037 2158 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
duke@435 2159 if (k_o == NULL) return NULL;
duke@435 2160 }
duke@435 2161 instanceKlassHandle k(THREAD, k_o);
coleenp@2497 2162 Symbol* name = cp->uncached_name_ref_at(index);
coleenp@2497 2163 Symbol* sig = cp->uncached_signature_ref_at(index);
duke@435 2164 methodHandle m (THREAD, k->find_method(name, sig));
duke@435 2165 if (m.is_null()) {
duke@435 2166 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
duke@435 2167 }
duke@435 2168 oop method;
duke@435 2169 if (!m->is_initializer() || m->is_static()) {
duke@435 2170 method = Reflection::new_method(m, true, true, CHECK_NULL);
duke@435 2171 } else {
duke@435 2172 method = Reflection::new_constructor(m, CHECK_NULL);
duke@435 2173 }
duke@435 2174 return JNIHandles::make_local(method);
duke@435 2175 }
duke@435 2176
coleenp@4037 2177 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2178 {
duke@435 2179 JVMWrapper("JVM_ConstantPoolGetMethodAt");
duke@435 2180 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2181 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2182 bounds_check(cp, index, CHECK_NULL);
duke@435 2183 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
duke@435 2184 return res;
duke@435 2185 }
duke@435 2186 JVM_END
duke@435 2187
coleenp@4037 2188 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2189 {
duke@435 2190 JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
duke@435 2191 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2192 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2193 bounds_check(cp, index, CHECK_NULL);
duke@435 2194 jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);
duke@435 2195 return res;
duke@435 2196 }
duke@435 2197 JVM_END
duke@435 2198
duke@435 2199 static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
duke@435 2200 constantTag tag = cp->tag_at(index);
duke@435 2201 if (!tag.is_field()) {
duke@435 2202 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2203 }
duke@435 2204 int klass_ref = cp->uncached_klass_ref_index_at(index);
coleenp@4037 2205 Klass* k_o;
duke@435 2206 if (force_resolution) {
duke@435 2207 k_o = cp->klass_at(klass_ref, CHECK_NULL);
duke@435 2208 } else {
coleenp@4037 2209 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
duke@435 2210 if (k_o == NULL) return NULL;
duke@435 2211 }
duke@435 2212 instanceKlassHandle k(THREAD, k_o);
coleenp@2497 2213 Symbol* name = cp->uncached_name_ref_at(index);
coleenp@2497 2214 Symbol* sig = cp->uncached_signature_ref_at(index);
duke@435 2215 fieldDescriptor fd;
coleenp@4037 2216 Klass* target_klass = k->find_field(name, sig, &fd);
duke@435 2217 if (target_klass == NULL) {
duke@435 2218 THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class");
duke@435 2219 }
duke@435 2220 oop field = Reflection::new_field(&fd, true, CHECK_NULL);
duke@435 2221 return JNIHandles::make_local(field);
duke@435 2222 }
duke@435 2223
coleenp@4037 2224 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index))
duke@435 2225 {
duke@435 2226 JVMWrapper("JVM_ConstantPoolGetFieldAt");
duke@435 2227 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2228 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2229 bounds_check(cp, index, CHECK_NULL);
duke@435 2230 jobject res = get_field_at_helper(cp, index, true, CHECK_NULL);
duke@435 2231 return res;
duke@435 2232 }
duke@435 2233 JVM_END
duke@435 2234
coleenp@4037 2235 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2236 {
duke@435 2237 JVMWrapper("JVM_ConstantPoolGetFieldAtIfLoaded");
duke@435 2238 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2239 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2240 bounds_check(cp, index, CHECK_NULL);
duke@435 2241 jobject res = get_field_at_helper(cp, index, false, CHECK_NULL);
duke@435 2242 return res;
duke@435 2243 }
duke@435 2244 JVM_END
duke@435 2245
coleenp@4037 2246 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2247 {
duke@435 2248 JVMWrapper("JVM_ConstantPoolGetMemberRefInfoAt");
duke@435 2249 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2250 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2251 bounds_check(cp, index, CHECK_NULL);
duke@435 2252 constantTag tag = cp->tag_at(index);
duke@435 2253 if (!tag.is_field_or_method()) {
duke@435 2254 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2255 }
duke@435 2256 int klass_ref = cp->uncached_klass_ref_index_at(index);
coleenp@2497 2257 Symbol* klass_name = cp->klass_name_at(klass_ref);
coleenp@2497 2258 Symbol* member_name = cp->uncached_name_ref_at(index);
coleenp@2497 2259 Symbol* member_sig = cp->uncached_signature_ref_at(index);
never@1577 2260 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), 3, CHECK_NULL);
duke@435 2261 objArrayHandle dest(THREAD, dest_o);
duke@435 2262 Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL);
duke@435 2263 dest->obj_at_put(0, str());
duke@435 2264 str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
duke@435 2265 dest->obj_at_put(1, str());
duke@435 2266 str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
duke@435 2267 dest->obj_at_put(2, str());
duke@435 2268 return (jobjectArray) JNIHandles::make_local(dest());
duke@435 2269 }
duke@435 2270 JVM_END
duke@435 2271
coleenp@4037 2272 JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2273 {
duke@435 2274 JVMWrapper("JVM_ConstantPoolGetIntAt");
coleenp@4037 2275 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2276 bounds_check(cp, index, CHECK_0);
duke@435 2277 constantTag tag = cp->tag_at(index);
duke@435 2278 if (!tag.is_int()) {
duke@435 2279 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2280 }
duke@435 2281 return cp->int_at(index);
duke@435 2282 }
duke@435 2283 JVM_END
duke@435 2284
coleenp@4037 2285 JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2286 {
duke@435 2287 JVMWrapper("JVM_ConstantPoolGetLongAt");
coleenp@4037 2288 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2289 bounds_check(cp, index, CHECK_(0L));
duke@435 2290 constantTag tag = cp->tag_at(index);
duke@435 2291 if (!tag.is_long()) {
duke@435 2292 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2293 }
duke@435 2294 return cp->long_at(index);
duke@435 2295 }
duke@435 2296 JVM_END
duke@435 2297
coleenp@4037 2298 JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2299 {
duke@435 2300 JVMWrapper("JVM_ConstantPoolGetFloatAt");
coleenp@4037 2301 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2302 bounds_check(cp, index, CHECK_(0.0f));
duke@435 2303 constantTag tag = cp->tag_at(index);
duke@435 2304 if (!tag.is_float()) {
duke@435 2305 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2306 }
duke@435 2307 return cp->float_at(index);
duke@435 2308 }
duke@435 2309 JVM_END
duke@435 2310
coleenp@4037 2311 JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2312 {
duke@435 2313 JVMWrapper("JVM_ConstantPoolGetDoubleAt");
coleenp@4037 2314 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2315 bounds_check(cp, index, CHECK_(0.0));
duke@435 2316 constantTag tag = cp->tag_at(index);
duke@435 2317 if (!tag.is_double()) {
duke@435 2318 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2319 }
duke@435 2320 return cp->double_at(index);
duke@435 2321 }
duke@435 2322 JVM_END
duke@435 2323
coleenp@4037 2324 JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2325 {
duke@435 2326 JVMWrapper("JVM_ConstantPoolGetStringAt");
coleenp@4037 2327 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2328 bounds_check(cp, index, CHECK_NULL);
duke@435 2329 constantTag tag = cp->tag_at(index);
coleenp@4037 2330 if (!tag.is_string()) {
duke@435 2331 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2332 }
duke@435 2333 oop str = cp->string_at(index, CHECK_NULL);
duke@435 2334 return (jstring) JNIHandles::make_local(str);
duke@435 2335 }
duke@435 2336 JVM_END
duke@435 2337
coleenp@4037 2338 JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index))
duke@435 2339 {
duke@435 2340 JVMWrapper("JVM_ConstantPoolGetUTF8At");
duke@435 2341 JvmtiVMObjectAllocEventCollector oam;
coleenp@4037 2342 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
duke@435 2343 bounds_check(cp, index, CHECK_NULL);
duke@435 2344 constantTag tag = cp->tag_at(index);
duke@435 2345 if (!tag.is_symbol()) {
duke@435 2346 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
duke@435 2347 }
coleenp@2497 2348 Symbol* sym = cp->symbol_at(index);
duke@435 2349 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
duke@435 2350 return (jstring) JNIHandles::make_local(str());
duke@435 2351 }
duke@435 2352 JVM_END
duke@435 2353
duke@435 2354
duke@435 2355 // Assertion support. //////////////////////////////////////////////////////////
duke@435 2356
duke@435 2357 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
duke@435 2358 JVMWrapper("JVM_DesiredAssertionStatus");
duke@435 2359 assert(cls != NULL, "bad class");
duke@435 2360
duke@435 2361 oop r = JNIHandles::resolve(cls);
duke@435 2362 assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed");
duke@435 2363 if (java_lang_Class::is_primitive(r)) return false;
duke@435 2364
coleenp@4037 2365 Klass* k = java_lang_Class::as_Klass(r);
hseigel@4278 2366 assert(k->oop_is_instance(), "must be an instance klass");
hseigel@4278 2367 if (! k->oop_is_instance()) return false;
duke@435 2368
duke@435 2369 ResourceMark rm(THREAD);
hseigel@4278 2370 const char* name = k->name()->as_C_string();
hseigel@4278 2371 bool system_class = k->class_loader() == NULL;
duke@435 2372 return JavaAssertions::enabled(name, system_class);
duke@435 2373
duke@435 2374 JVM_END
duke@435 2375
duke@435 2376
duke@435 2377 // Return a new AssertionStatusDirectives object with the fields filled in with
duke@435 2378 // command-line assertion arguments (i.e., -ea, -da).
duke@435 2379 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
duke@435 2380 JVMWrapper("JVM_AssertionStatusDirectives");
duke@435 2381 JvmtiVMObjectAllocEventCollector oam;
duke@435 2382 oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
duke@435 2383 return JNIHandles::make_local(env, asd);
duke@435 2384 JVM_END
duke@435 2385
duke@435 2386 // Verification ////////////////////////////////////////////////////////////////////////////////
duke@435 2387
duke@435 2388 // Reflection for the verifier /////////////////////////////////////////////////////////////////
duke@435 2389
duke@435 2390 // RedefineClasses support: bug 6214132 caused verification to fail.
duke@435 2391 // All functions from this section should call the jvmtiThreadSate function:
coleenp@4037 2392 // Klass* class_to_verify_considering_redefinition(Klass* klass).
coleenp@4037 2393 // The function returns a Klass* of the _scratch_class if the verifier
duke@435 2394 // was invoked in the middle of the class redefinition.
coleenp@4037 2395 // Otherwise it returns its argument value which is the _the_class Klass*.
duke@435 2396 // Please, refer to the description in the jvmtiThreadSate.hpp.
duke@435 2397
duke@435 2398 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
duke@435 2399 JVMWrapper("JVM_GetClassNameUTF");
coleenp@4037 2400 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2401 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
hseigel@4278 2402 return k->name()->as_utf8();
duke@435 2403 JVM_END
duke@435 2404
duke@435 2405
duke@435 2406 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
duke@435 2407 JVMWrapper("JVM_GetClassCPTypes");
coleenp@4037 2408 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2409 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2410 // types will have length zero if this is not an InstanceKlass
duke@435 2411 // (length is determined by call to JVM_GetClassCPEntriesCount)
hseigel@4278 2412 if (k->oop_is_instance()) {
coleenp@4037 2413 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2414 for (int index = cp->length() - 1; index >= 0; index--) {
duke@435 2415 constantTag tag = cp->tag_at(index);
coleenp@4037 2416 types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value();
duke@435 2417 }
duke@435 2418 }
duke@435 2419 JVM_END
duke@435 2420
duke@435 2421
duke@435 2422 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
duke@435 2423 JVMWrapper("JVM_GetClassCPEntriesCount");
coleenp@4037 2424 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2425 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
hseigel@4278 2426 if (!k->oop_is_instance())
duke@435 2427 return 0;
coleenp@4037 2428 return InstanceKlass::cast(k)->constants()->length();
duke@435 2429 JVM_END
duke@435 2430
duke@435 2431
duke@435 2432 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
duke@435 2433 JVMWrapper("JVM_GetClassFieldsCount");
coleenp@4037 2434 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2435 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
hseigel@4278 2436 if (!k->oop_is_instance())
duke@435 2437 return 0;
coleenp@4037 2438 return InstanceKlass::cast(k)->java_fields_count();
duke@435 2439 JVM_END
duke@435 2440
duke@435 2441
duke@435 2442 JVM_QUICK_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
duke@435 2443 JVMWrapper("JVM_GetClassMethodsCount");
coleenp@4037 2444 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2445 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
hseigel@4278 2446 if (!k->oop_is_instance())
duke@435 2447 return 0;
coleenp@4037 2448 return InstanceKlass::cast(k)->methods()->length();
duke@435 2449 JVM_END
duke@435 2450
duke@435 2451
duke@435 2452 // The following methods, used for the verifier, are never called with
coleenp@4037 2453 // array klasses, so a direct cast to InstanceKlass is safe.
duke@435 2454 // Typically, these methods are called in a loop with bounds determined
duke@435 2455 // by the results of JVM_GetClass{Fields,Methods}Count, which return
duke@435 2456 // zero for arrays.
duke@435 2457 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
duke@435 2458 JVMWrapper("JVM_GetMethodIxExceptionIndexes");
coleenp@4037 2459 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2460 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2461 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2462 int length = method->checked_exceptions_length();
duke@435 2463 if (length > 0) {
coleenp@4037 2464 CheckedExceptionElement* table= method->checked_exceptions_start();
duke@435 2465 for (int i = 0; i < length; i++) {
duke@435 2466 exceptions[i] = table[i].class_cp_index;
duke@435 2467 }
duke@435 2468 }
duke@435 2469 JVM_END
duke@435 2470
duke@435 2471
duke@435 2472 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
duke@435 2473 JVMWrapper("JVM_GetMethodIxExceptionsCount");
coleenp@4037 2474 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2475 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2476 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2477 return method->checked_exceptions_length();
duke@435 2478 JVM_END
duke@435 2479
duke@435 2480
duke@435 2481 JVM_QUICK_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
duke@435 2482 JVMWrapper("JVM_GetMethodIxByteCode");
coleenp@4037 2483 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2484 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2485 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2486 memcpy(code, method->code_base(), method->code_size());
duke@435 2487 JVM_END
duke@435 2488
duke@435 2489
duke@435 2490 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
duke@435 2491 JVMWrapper("JVM_GetMethodIxByteCodeLength");
coleenp@4037 2492 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2493 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2494 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2495 return method->code_size();
duke@435 2496 JVM_END
duke@435 2497
duke@435 2498
duke@435 2499 JVM_QUICK_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
duke@435 2500 JVMWrapper("JVM_GetMethodIxExceptionTableEntry");
coleenp@4037 2501 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2502 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2503 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2504 ExceptionTable extable(method);
jiangli@3917 2505 entry->start_pc = extable.start_pc(entry_index);
jiangli@3917 2506 entry->end_pc = extable.end_pc(entry_index);
jiangli@3917 2507 entry->handler_pc = extable.handler_pc(entry_index);
jiangli@3917 2508 entry->catchType = extable.catch_type_index(entry_index);
duke@435 2509 JVM_END
duke@435 2510
duke@435 2511
duke@435 2512 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
duke@435 2513 JVMWrapper("JVM_GetMethodIxExceptionTableLength");
coleenp@4037 2514 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2515 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2516 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2517 return method->exception_table_length();
duke@435 2518 JVM_END
duke@435 2519
duke@435 2520
duke@435 2521 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
duke@435 2522 JVMWrapper("JVM_GetMethodIxModifiers");
coleenp@4037 2523 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2524 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2525 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2526 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
duke@435 2527 JVM_END
duke@435 2528
duke@435 2529
duke@435 2530 JVM_QUICK_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
duke@435 2531 JVMWrapper("JVM_GetFieldIxModifiers");
coleenp@4037 2532 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2533 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2534 return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
duke@435 2535 JVM_END
duke@435 2536
duke@435 2537
duke@435 2538 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
duke@435 2539 JVMWrapper("JVM_GetMethodIxLocalsCount");
coleenp@4037 2540 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2541 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2542 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2543 return method->max_locals();
duke@435 2544 JVM_END
duke@435 2545
duke@435 2546
duke@435 2547 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
duke@435 2548 JVMWrapper("JVM_GetMethodIxArgsSize");
coleenp@4037 2549 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2550 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2551 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2552 return method->size_of_parameters();
duke@435 2553 JVM_END
duke@435 2554
duke@435 2555
duke@435 2556 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
duke@435 2557 JVMWrapper("JVM_GetMethodIxMaxStack");
coleenp@4037 2558 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2559 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2560 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2561 return method->verifier_max_stack();
duke@435 2562 JVM_END
duke@435 2563
duke@435 2564
duke@435 2565 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
duke@435 2566 JVMWrapper("JVM_IsConstructorIx");
duke@435 2567 ResourceMark rm(THREAD);
coleenp@4037 2568 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2569 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2570 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2571 return method->name() == vmSymbols::object_initializer_name();
duke@435 2572 JVM_END
duke@435 2573
duke@435 2574
acorn@4499 2575 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
acorn@4499 2576 JVMWrapper("JVM_IsVMGeneratedMethodIx");
acorn@4499 2577 ResourceMark rm(THREAD);
acorn@4499 2578 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
acorn@4499 2579 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
acorn@4499 2580 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
acorn@4499 2581 return method->is_overpass();
acorn@4499 2582 JVM_END
acorn@4499 2583
duke@435 2584 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
duke@435 2585 JVMWrapper("JVM_GetMethodIxIxUTF");
coleenp@4037 2586 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2587 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2588 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2589 return method->name()->as_utf8();
duke@435 2590 JVM_END
duke@435 2591
duke@435 2592
duke@435 2593 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
duke@435 2594 JVMWrapper("JVM_GetMethodIxSignatureUTF");
coleenp@4037 2595 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2596 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2597 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
coleenp@4037 2598 return method->signature()->as_utf8();
duke@435 2599 JVM_END
duke@435 2600
duke@435 2601 /**
duke@435 2602 * All of these JVM_GetCP-xxx methods are used by the old verifier to
duke@435 2603 * read entries in the constant pool. Since the old verifier always
duke@435 2604 * works on a copy of the code, it will not see any rewriting that
duke@435 2605 * may possibly occur in the middle of verification. So it is important
duke@435 2606 * that nothing it calls tries to use the cpCache instead of the raw
duke@435 2607 * constant pool, so we must use cp->uncached_x methods when appropriate.
duke@435 2608 */
duke@435 2609 JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2610 JVMWrapper("JVM_GetCPFieldNameUTF");
coleenp@4037 2611 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2612 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2613 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2614 switch (cp->tag_at(cp_index).value()) {
duke@435 2615 case JVM_CONSTANT_Fieldref:
duke@435 2616 return cp->uncached_name_ref_at(cp_index)->as_utf8();
duke@435 2617 default:
duke@435 2618 fatal("JVM_GetCPFieldNameUTF: illegal constant");
duke@435 2619 }
duke@435 2620 ShouldNotReachHere();
duke@435 2621 return NULL;
duke@435 2622 JVM_END
duke@435 2623
duke@435 2624
duke@435 2625 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2626 JVMWrapper("JVM_GetCPMethodNameUTF");
coleenp@4037 2627 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2628 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2629 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2630 switch (cp->tag_at(cp_index).value()) {
duke@435 2631 case JVM_CONSTANT_InterfaceMethodref:
duke@435 2632 case JVM_CONSTANT_Methodref:
duke@435 2633 return cp->uncached_name_ref_at(cp_index)->as_utf8();
duke@435 2634 default:
duke@435 2635 fatal("JVM_GetCPMethodNameUTF: illegal constant");
duke@435 2636 }
duke@435 2637 ShouldNotReachHere();
duke@435 2638 return NULL;
duke@435 2639 JVM_END
duke@435 2640
duke@435 2641
duke@435 2642 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2643 JVMWrapper("JVM_GetCPMethodSignatureUTF");
coleenp@4037 2644 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2645 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2646 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2647 switch (cp->tag_at(cp_index).value()) {
duke@435 2648 case JVM_CONSTANT_InterfaceMethodref:
duke@435 2649 case JVM_CONSTANT_Methodref:
duke@435 2650 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
duke@435 2651 default:
duke@435 2652 fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
duke@435 2653 }
duke@435 2654 ShouldNotReachHere();
duke@435 2655 return NULL;
duke@435 2656 JVM_END
duke@435 2657
duke@435 2658
duke@435 2659 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2660 JVMWrapper("JVM_GetCPFieldSignatureUTF");
coleenp@4037 2661 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2662 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2663 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2664 switch (cp->tag_at(cp_index).value()) {
duke@435 2665 case JVM_CONSTANT_Fieldref:
duke@435 2666 return cp->uncached_signature_ref_at(cp_index)->as_utf8();
duke@435 2667 default:
duke@435 2668 fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
duke@435 2669 }
duke@435 2670 ShouldNotReachHere();
duke@435 2671 return NULL;
duke@435 2672 JVM_END
duke@435 2673
duke@435 2674
duke@435 2675 JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2676 JVMWrapper("JVM_GetCPClassNameUTF");
coleenp@4037 2677 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2678 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2679 ConstantPool* cp = InstanceKlass::cast(k)->constants();
coleenp@2497 2680 Symbol* classname = cp->klass_name_at(cp_index);
duke@435 2681 return classname->as_utf8();
duke@435 2682 JVM_END
duke@435 2683
duke@435 2684
duke@435 2685 JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2686 JVMWrapper("JVM_GetCPFieldClassNameUTF");
coleenp@4037 2687 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2688 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2689 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2690 switch (cp->tag_at(cp_index).value()) {
duke@435 2691 case JVM_CONSTANT_Fieldref: {
duke@435 2692 int class_index = cp->uncached_klass_ref_index_at(cp_index);
coleenp@2497 2693 Symbol* classname = cp->klass_name_at(class_index);
duke@435 2694 return classname->as_utf8();
duke@435 2695 }
duke@435 2696 default:
duke@435 2697 fatal("JVM_GetCPFieldClassNameUTF: illegal constant");
duke@435 2698 }
duke@435 2699 ShouldNotReachHere();
duke@435 2700 return NULL;
duke@435 2701 JVM_END
duke@435 2702
duke@435 2703
duke@435 2704 JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
duke@435 2705 JVMWrapper("JVM_GetCPMethodClassNameUTF");
coleenp@4037 2706 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
duke@435 2707 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
coleenp@4037 2708 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2709 switch (cp->tag_at(cp_index).value()) {
duke@435 2710 case JVM_CONSTANT_Methodref:
duke@435 2711 case JVM_CONSTANT_InterfaceMethodref: {
duke@435 2712 int class_index = cp->uncached_klass_ref_index_at(cp_index);
coleenp@2497 2713 Symbol* classname = cp->klass_name_at(class_index);
duke@435 2714 return classname->as_utf8();
duke@435 2715 }
duke@435 2716 default:
duke@435 2717 fatal("JVM_GetCPMethodClassNameUTF: illegal constant");
duke@435 2718 }
duke@435 2719 ShouldNotReachHere();
duke@435 2720 return NULL;
duke@435 2721 JVM_END
duke@435 2722
duke@435 2723
never@3137 2724 JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
duke@435 2725 JVMWrapper("JVM_GetCPFieldModifiers");
coleenp@4037 2726 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
coleenp@4037 2727 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
duke@435 2728 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
duke@435 2729 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
coleenp@4037 2730 ConstantPool* cp = InstanceKlass::cast(k)->constants();
coleenp@4037 2731 ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants();
duke@435 2732 switch (cp->tag_at(cp_index).value()) {
duke@435 2733 case JVM_CONSTANT_Fieldref: {
coleenp@2497 2734 Symbol* name = cp->uncached_name_ref_at(cp_index);
coleenp@2497 2735 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
never@3137 2736 for (JavaFieldStream fs(k_called); !fs.done(); fs.next()) {
never@3137 2737 if (fs.name() == name && fs.signature() == signature) {
never@3137 2738 return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS;
duke@435 2739 }
duke@435 2740 }
duke@435 2741 return -1;
duke@435 2742 }
duke@435 2743 default:
duke@435 2744 fatal("JVM_GetCPFieldModifiers: illegal constant");
duke@435 2745 }
duke@435 2746 ShouldNotReachHere();
duke@435 2747 return 0;
duke@435 2748 JVM_END
duke@435 2749
duke@435 2750
duke@435 2751 JVM_QUICK_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
duke@435 2752 JVMWrapper("JVM_GetCPMethodModifiers");
coleenp@4037 2753 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
coleenp@4037 2754 Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
duke@435 2755 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
duke@435 2756 k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
coleenp@4037 2757 ConstantPool* cp = InstanceKlass::cast(k)->constants();
duke@435 2758 switch (cp->tag_at(cp_index).value()) {
duke@435 2759 case JVM_CONSTANT_Methodref:
duke@435 2760 case JVM_CONSTANT_InterfaceMethodref: {
coleenp@2497 2761 Symbol* name = cp->uncached_name_ref_at(cp_index);
coleenp@2497 2762 Symbol* signature = cp->uncached_signature_ref_at(cp_index);
coleenp@4037 2763 Array<Method*>* methods = InstanceKlass::cast(k_called)->methods();
duke@435 2764 int methods_count = methods->length();
duke@435 2765 for (int i = 0; i < methods_count; i++) {
coleenp@4037 2766 Method* method = methods->at(i);
duke@435 2767 if (method->name() == name && method->signature() == signature) {
duke@435 2768 return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
duke@435 2769 }
duke@435 2770 }
duke@435 2771 return -1;
duke@435 2772 }
duke@435 2773 default:
duke@435 2774 fatal("JVM_GetCPMethodModifiers: illegal constant");
duke@435 2775 }
duke@435 2776 ShouldNotReachHere();
duke@435 2777 return 0;
duke@435 2778 JVM_END
duke@435 2779
duke@435 2780
duke@435 2781 // Misc //////////////////////////////////////////////////////////////////////////////////////////////
duke@435 2782
duke@435 2783 JVM_LEAF(void, JVM_ReleaseUTF(const char *utf))
duke@435 2784 // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything
duke@435 2785 JVM_END
duke@435 2786
duke@435 2787
duke@435 2788 JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2))
duke@435 2789 JVMWrapper("JVM_IsSameClassPackage");
duke@435 2790 oop class1_mirror = JNIHandles::resolve_non_null(class1);
duke@435 2791 oop class2_mirror = JNIHandles::resolve_non_null(class2);
coleenp@4037 2792 Klass* klass1 = java_lang_Class::as_Klass(class1_mirror);
coleenp@4037 2793 Klass* klass2 = java_lang_Class::as_Klass(class2_mirror);
duke@435 2794 return (jboolean) Reflection::is_same_class_package(klass1, klass2);
duke@435 2795 JVM_END
duke@435 2796
duke@435 2797
duke@435 2798 // IO functions ////////////////////////////////////////////////////////////////////////////////////////
duke@435 2799
duke@435 2800 JVM_LEAF(jint, JVM_Open(const char *fname, jint flags, jint mode))
duke@435 2801 JVMWrapper2("JVM_Open (%s)", fname);
duke@435 2802
duke@435 2803 //%note jvm_r6
ikrylov@2322 2804 int result = os::open(fname, flags, mode);
duke@435 2805 if (result >= 0) {
duke@435 2806 return result;
duke@435 2807 } else {
duke@435 2808 switch(errno) {
duke@435 2809 case EEXIST:
duke@435 2810 return JVM_EEXIST;
duke@435 2811 default:
duke@435 2812 return -1;
duke@435 2813 }
duke@435 2814 }
duke@435 2815 JVM_END
duke@435 2816
duke@435 2817
duke@435 2818 JVM_LEAF(jint, JVM_Close(jint fd))
duke@435 2819 JVMWrapper2("JVM_Close (0x%x)", fd);
duke@435 2820 //%note jvm_r6
ikrylov@2322 2821 return os::close(fd);
duke@435 2822 JVM_END
duke@435 2823
duke@435 2824
duke@435 2825 JVM_LEAF(jint, JVM_Read(jint fd, char *buf, jint nbytes))
duke@435 2826 JVMWrapper2("JVM_Read (0x%x)", fd);
duke@435 2827
duke@435 2828 //%note jvm_r6
ikrylov@2322 2829 return (jint)os::restartable_read(fd, buf, nbytes);
duke@435 2830 JVM_END
duke@435 2831
duke@435 2832
duke@435 2833 JVM_LEAF(jint, JVM_Write(jint fd, char *buf, jint nbytes))
duke@435 2834 JVMWrapper2("JVM_Write (0x%x)", fd);
duke@435 2835
duke@435 2836 //%note jvm_r6
ikrylov@2322 2837 return (jint)os::write(fd, buf, nbytes);
duke@435 2838 JVM_END
duke@435 2839
duke@435 2840
duke@435 2841 JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes))
duke@435 2842 JVMWrapper2("JVM_Available (0x%x)", fd);
duke@435 2843 //%note jvm_r6
ikrylov@2322 2844 return os::available(fd, pbytes);
duke@435 2845 JVM_END
duke@435 2846
duke@435 2847
duke@435 2848 JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence))
drchase@6680 2849 JVMWrapper4("JVM_Lseek (0x%x, " INT64_FORMAT ", %d)", fd, (int64_t) offset, whence);
duke@435 2850 //%note jvm_r6
ikrylov@2322 2851 return os::lseek(fd, offset, whence);
duke@435 2852 JVM_END
duke@435 2853
duke@435 2854
duke@435 2855 JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length))
drchase@6680 2856 JVMWrapper3("JVM_SetLength (0x%x, " INT64_FORMAT ")", fd, (int64_t) length);
ikrylov@2322 2857 return os::ftruncate(fd, length);
duke@435 2858 JVM_END
duke@435 2859
duke@435 2860
duke@435 2861 JVM_LEAF(jint, JVM_Sync(jint fd))
duke@435 2862 JVMWrapper2("JVM_Sync (0x%x)", fd);
duke@435 2863 //%note jvm_r6
ikrylov@2322 2864 return os::fsync(fd);
duke@435 2865 JVM_END
duke@435 2866
duke@435 2867
duke@435 2868 // Printing support //////////////////////////////////////////////////
duke@435 2869 extern "C" {
duke@435 2870
drchase@6680 2871 ATTRIBUTE_PRINTF(3, 0)
duke@435 2872 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
duke@435 2873 // see bug 4399518, 4417214
duke@435 2874 if ((intptr_t)count <= 0) return -1;
shshahma@8584 2875
shshahma@8584 2876 int result = vsnprintf(str, count, fmt, args);
shshahma@8584 2877 // Note: on truncation vsnprintf(3) on Unix returns number of
shshahma@8584 2878 // characters which would have been written had the buffer been large
shshahma@8584 2879 // enough; on Windows, it returns -1. We handle both cases here and
shshahma@8584 2880 // always return -1, and perform null termination.
shshahma@8584 2881 if ((result > 0 && (size_t)result >= count) || result == -1) {
shshahma@8584 2882 str[count - 1] = '\0';
shshahma@8584 2883 result = -1;
shshahma@8584 2884 }
shshahma@8584 2885
shshahma@8584 2886 return result;
duke@435 2887 }
duke@435 2888
drchase@6680 2889 ATTRIBUTE_PRINTF(3, 0)
duke@435 2890 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
duke@435 2891 va_list args;
duke@435 2892 int len;
duke@435 2893 va_start(args, fmt);
duke@435 2894 len = jio_vsnprintf(str, count, fmt, args);
duke@435 2895 va_end(args);
duke@435 2896 return len;
duke@435 2897 }
duke@435 2898
drchase@6680 2899 ATTRIBUTE_PRINTF(2,3)
duke@435 2900 int jio_fprintf(FILE* f, const char *fmt, ...) {
duke@435 2901 int len;
duke@435 2902 va_list args;
duke@435 2903 va_start(args, fmt);
duke@435 2904 len = jio_vfprintf(f, fmt, args);
duke@435 2905 va_end(args);
duke@435 2906 return len;
duke@435 2907 }
duke@435 2908
drchase@6680 2909 ATTRIBUTE_PRINTF(2, 0)
duke@435 2910 int jio_vfprintf(FILE* f, const char *fmt, va_list args) {
duke@435 2911 if (Arguments::vfprintf_hook() != NULL) {
duke@435 2912 return Arguments::vfprintf_hook()(f, fmt, args);
duke@435 2913 } else {
duke@435 2914 return vfprintf(f, fmt, args);
duke@435 2915 }
duke@435 2916 }
duke@435 2917
drchase@6680 2918 ATTRIBUTE_PRINTF(1, 2)
coleenp@2507 2919 JNIEXPORT int jio_printf(const char *fmt, ...) {
duke@435 2920 int len;
duke@435 2921 va_list args;
duke@435 2922 va_start(args, fmt);
duke@435 2923 len = jio_vfprintf(defaultStream::output_stream(), fmt, args);
duke@435 2924 va_end(args);
duke@435 2925 return len;
duke@435 2926 }
duke@435 2927
duke@435 2928
duke@435 2929 // HotSpot specific jio method
duke@435 2930 void jio_print(const char* s) {
duke@435 2931 // Try to make this function as atomic as possible.
duke@435 2932 if (Arguments::vfprintf_hook() != NULL) {
duke@435 2933 jio_fprintf(defaultStream::output_stream(), "%s", s);
duke@435 2934 } else {
xlu@948 2935 // Make an unused local variable to avoid warning from gcc 4.x compiler.
xlu@948 2936 size_t count = ::write(defaultStream::output_fd(), s, (int)strlen(s));
duke@435 2937 }
duke@435 2938 }
duke@435 2939
duke@435 2940 } // Extern C
duke@435 2941
duke@435 2942 // java.lang.Thread //////////////////////////////////////////////////////////////////////////////
duke@435 2943
duke@435 2944 // In most of the JVM Thread support functions we need to be sure to lock the Threads_lock
duke@435 2945 // to prevent the target thread from exiting after we have a pointer to the C++ Thread or
duke@435 2946 // OSThread objects. The exception to this rule is when the target object is the thread
duke@435 2947 // doing the operation, in which case we know that the thread won't exit until the
duke@435 2948 // operation is done (all exits being voluntary). There are a few cases where it is
duke@435 2949 // rather silly to do operations on yourself, like resuming yourself or asking whether
duke@435 2950 // you are alive. While these can still happen, they are not subject to deadlocks if
duke@435 2951 // the lock is held while the operation occurs (this is not the case for suspend, for
duke@435 2952 // instance), and are very unlikely. Because IsAlive needs to be fast and its
duke@435 2953 // implementation is local to this file, we always lock Threads_lock for that one.
duke@435 2954
duke@435 2955 static void thread_entry(JavaThread* thread, TRAPS) {
duke@435 2956 HandleMark hm(THREAD);
duke@435 2957 Handle obj(THREAD, thread->threadObj());
duke@435 2958 JavaValue result(T_VOID);
duke@435 2959 JavaCalls::call_virtual(&result,
duke@435 2960 obj,
never@1577 2961 KlassHandle(THREAD, SystemDictionary::Thread_klass()),
coleenp@2497 2962 vmSymbols::run_method_name(),
coleenp@2497 2963 vmSymbols::void_method_signature(),
duke@435 2964 THREAD);
duke@435 2965 }
duke@435 2966
duke@435 2967
duke@435 2968 JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
duke@435 2969 JVMWrapper("JVM_StartThread");
duke@435 2970 JavaThread *native_thread = NULL;
duke@435 2971
duke@435 2972 // We cannot hold the Threads_lock when we throw an exception,
duke@435 2973 // due to rank ordering issues. Example: we might need to grab the
duke@435 2974 // Heap_lock while we construct the exception.
duke@435 2975 bool throw_illegal_thread_state = false;
duke@435 2976
duke@435 2977 // We must release the Threads_lock before we can post a jvmti event
duke@435 2978 // in Thread::start.
duke@435 2979 {
duke@435 2980 // Ensure that the C++ Thread and OSThread structures aren't freed before
duke@435 2981 // we operate.
duke@435 2982 MutexLocker mu(Threads_lock);
duke@435 2983
dholmes@2482 2984 // Since JDK 5 the java.lang.Thread threadStatus is used to prevent
dholmes@2482 2985 // re-starting an already started thread, so we should usually find
dholmes@2482 2986 // that the JavaThread is null. However for a JNI attached thread
dholmes@2482 2987 // there is a small window between the Thread object being created
dholmes@2482 2988 // (with its JavaThread set) and the update to its threadStatus, so we
dholmes@2482 2989 // have to check for this
dholmes@2482 2990 if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) {
dholmes@2482 2991 throw_illegal_thread_state = true;
duke@435 2992 } else {
dholmes@2482 2993 // We could also check the stillborn flag to see if this thread was already stopped, but
dholmes@2482 2994 // for historical reasons we let the thread detect that itself when it starts running
dholmes@2482 2995
duke@435 2996 jlong size =
duke@435 2997 java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread));
duke@435 2998 // Allocate the C++ Thread structure and create the native thread. The
duke@435 2999 // stack size retrieved from java is signed, but the constructor takes
duke@435 3000 // size_t (an unsigned type), so avoid passing negative values which would
duke@435 3001 // result in really large stacks.
duke@435 3002 size_t sz = size > 0 ? (size_t) size : 0;
duke@435 3003 native_thread = new JavaThread(&thread_entry, sz);
duke@435 3004
duke@435 3005 // At this point it may be possible that no osthread was created for the
duke@435 3006 // JavaThread due to lack of memory. Check for this situation and throw
duke@435 3007 // an exception if necessary. Eventually we may want to change this so
duke@435 3008 // that we only grab the lock if the thread was created successfully -
duke@435 3009 // then we can also do this check and throw the exception in the
duke@435 3010 // JavaThread constructor.
duke@435 3011 if (native_thread->osthread() != NULL) {
duke@435 3012 // Note: the current thread is not being used within "prepare".
duke@435 3013 native_thread->prepare(jthread);
duke@435 3014 }
duke@435 3015 }
duke@435 3016 }
duke@435 3017
duke@435 3018 if (throw_illegal_thread_state) {
duke@435 3019 THROW(vmSymbols::java_lang_IllegalThreadStateException());
duke@435 3020 }
duke@435 3021
duke@435 3022 assert(native_thread != NULL, "Starting null thread?");
duke@435 3023
duke@435 3024 if (native_thread->osthread() == NULL) {
duke@435 3025 // No one should hold a reference to the 'native_thread'.
duke@435 3026 delete native_thread;
duke@435 3027 if (JvmtiExport::should_post_resource_exhausted()) {
duke@435 3028 JvmtiExport::post_resource_exhausted(
duke@435 3029 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
duke@435 3030 "unable to create new native thread");
duke@435 3031 }
duke@435 3032 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
duke@435 3033 "unable to create new native thread");
duke@435 3034 }
duke@435 3035
duke@435 3036 Thread::start(native_thread);
duke@435 3037
duke@435 3038 JVM_END
duke@435 3039
duke@435 3040 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
duke@435 3041 // before the quasi-asynchronous exception is delivered. This is a little obtrusive,
duke@435 3042 // but is thought to be reliable and simple. In the case, where the receiver is the
dholmes@2482 3043 // same thread as the sender, no safepoint is needed.
duke@435 3044 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
duke@435 3045 JVMWrapper("JVM_StopThread");
duke@435 3046
duke@435 3047 oop java_throwable = JNIHandles::resolve(throwable);
duke@435 3048 if (java_throwable == NULL) {
duke@435 3049 THROW(vmSymbols::java_lang_NullPointerException());
duke@435 3050 }
duke@435 3051 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3052 JavaThread* receiver = java_lang_Thread::thread(java_thread);
never@3499 3053 Events::log_exception(JavaThread::current(),
never@3499 3054 "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
drchase@6680 3055 p2i(receiver), p2i((address)java_thread), p2i(throwable));
dholmes@2482 3056 // First check if thread is alive
duke@435 3057 if (receiver != NULL) {
duke@435 3058 // Check if exception is getting thrown at self (use oop equality, since the
duke@435 3059 // target object might exit)
duke@435 3060 if (java_thread == thread->threadObj()) {
duke@435 3061 THROW_OOP(java_throwable);
duke@435 3062 } else {
duke@435 3063 // Enques a VM_Operation to stop all threads and then deliver the exception...
duke@435 3064 Thread::send_async_exception(java_thread, JNIHandles::resolve(throwable));
duke@435 3065 }
duke@435 3066 }
dholmes@2482 3067 else {
dholmes@2482 3068 // Either:
dholmes@2482 3069 // - target thread has not been started before being stopped, or
dholmes@2482 3070 // - target thread already terminated
dholmes@2482 3071 // We could read the threadStatus to determine which case it is
dholmes@2482 3072 // but that is overkill as it doesn't matter. We must set the
dholmes@2482 3073 // stillborn flag for the first case, and if the thread has already
dholmes@2482 3074 // exited setting this flag has no affect
dholmes@2482 3075 java_lang_Thread::set_stillborn(java_thread);
dholmes@2482 3076 }
duke@435 3077 JVM_END
duke@435 3078
duke@435 3079
duke@435 3080 JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread))
duke@435 3081 JVMWrapper("JVM_IsThreadAlive");
duke@435 3082
duke@435 3083 oop thread_oop = JNIHandles::resolve_non_null(jthread);
duke@435 3084 return java_lang_Thread::is_alive(thread_oop);
duke@435 3085 JVM_END
duke@435 3086
duke@435 3087
duke@435 3088 JVM_ENTRY(void, JVM_SuspendThread(JNIEnv* env, jobject jthread))
duke@435 3089 JVMWrapper("JVM_SuspendThread");
duke@435 3090 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3091 JavaThread* receiver = java_lang_Thread::thread(java_thread);
duke@435 3092
duke@435 3093 if (receiver != NULL) {
duke@435 3094 // thread has run and has not exited (still on threads list)
duke@435 3095
duke@435 3096 {
duke@435 3097 MutexLockerEx ml(receiver->SR_lock(), Mutex::_no_safepoint_check_flag);
duke@435 3098 if (receiver->is_external_suspend()) {
duke@435 3099 // Don't allow nested external suspend requests. We can't return
duke@435 3100 // an error from this interface so just ignore the problem.
duke@435 3101 return;
duke@435 3102 }
duke@435 3103 if (receiver->is_exiting()) { // thread is in the process of exiting
duke@435 3104 return;
duke@435 3105 }
duke@435 3106 receiver->set_external_suspend();
duke@435 3107 }
duke@435 3108
duke@435 3109 // java_suspend() will catch threads in the process of exiting
duke@435 3110 // and will ignore them.
duke@435 3111 receiver->java_suspend();
duke@435 3112
duke@435 3113 // It would be nice to have the following assertion in all the
duke@435 3114 // time, but it is possible for a racing resume request to have
duke@435 3115 // resumed this thread right after we suspended it. Temporarily
duke@435 3116 // enable this assertion if you are chasing a different kind of
duke@435 3117 // bug.
duke@435 3118 //
duke@435 3119 // assert(java_lang_Thread::thread(receiver->threadObj()) == NULL ||
duke@435 3120 // receiver->is_being_ext_suspended(), "thread is not suspended");
duke@435 3121 }
duke@435 3122 JVM_END
duke@435 3123
duke@435 3124
duke@435 3125 JVM_ENTRY(void, JVM_ResumeThread(JNIEnv* env, jobject jthread))
duke@435 3126 JVMWrapper("JVM_ResumeThread");
duke@435 3127 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate.
duke@435 3128 // We need to *always* get the threads lock here, since this operation cannot be allowed during
duke@435 3129 // a safepoint. The safepoint code relies on suspending a thread to examine its state. If other
duke@435 3130 // threads randomly resumes threads, then a thread might not be suspended when the safepoint code
duke@435 3131 // looks at it.
duke@435 3132 MutexLocker ml(Threads_lock);
duke@435 3133 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
duke@435 3134 if (thr != NULL) {
duke@435 3135 // the thread has run and is not in the process of exiting
duke@435 3136 thr->java_resume();
duke@435 3137 }
duke@435 3138 JVM_END
duke@435 3139
duke@435 3140
duke@435 3141 JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio))
duke@435 3142 JVMWrapper("JVM_SetThreadPriority");
duke@435 3143 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
duke@435 3144 MutexLocker ml(Threads_lock);
duke@435 3145 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3146 java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
duke@435 3147 JavaThread* thr = java_lang_Thread::thread(java_thread);
duke@435 3148 if (thr != NULL) { // Thread not yet started; priority pushed down when it is
duke@435 3149 Thread::set_priority(thr, (ThreadPriority)prio);
duke@435 3150 }
duke@435 3151 JVM_END
duke@435 3152
duke@435 3153
duke@435 3154 JVM_ENTRY(void, JVM_Yield(JNIEnv *env, jclass threadClass))
duke@435 3155 JVMWrapper("JVM_Yield");
duke@435 3156 if (os::dont_yield()) return;
dcubed@3202 3157 #ifndef USDT2
fparain@1759 3158 HS_DTRACE_PROBE0(hotspot, thread__yield);
dcubed@3202 3159 #else /* USDT2 */
dcubed@3202 3160 HOTSPOT_THREAD_YIELD();
dcubed@3202 3161 #endif /* USDT2 */
duke@435 3162 // When ConvertYieldToSleep is off (default), this matches the classic VM use of yield.
duke@435 3163 // Critical for similar threading behaviour
duke@435 3164 if (ConvertYieldToSleep) {
duke@435 3165 os::sleep(thread, MinSleepInterval, false);
duke@435 3166 } else {
duke@435 3167 os::yield();
duke@435 3168 }
duke@435 3169 JVM_END
duke@435 3170
duke@435 3171
duke@435 3172 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
duke@435 3173 JVMWrapper("JVM_Sleep");
duke@435 3174
duke@435 3175 if (millis < 0) {
duke@435 3176 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
duke@435 3177 }
duke@435 3178
duke@435 3179 if (Thread::is_interrupted (THREAD, true) && !HAS_PENDING_EXCEPTION) {
duke@435 3180 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
duke@435 3181 }
duke@435 3182
duke@435 3183 // Save current thread state and restore it at the end of this block.
duke@435 3184 // And set new thread state to SLEEPING.
duke@435 3185 JavaThreadSleepState jtss(thread);
duke@435 3186
dcubed@3202 3187 #ifndef USDT2
fparain@1759 3188 HS_DTRACE_PROBE1(hotspot, thread__sleep__begin, millis);
dcubed@3202 3189 #else /* USDT2 */
dcubed@3202 3190 HOTSPOT_THREAD_SLEEP_BEGIN(
dcubed@3202 3191 millis);
dcubed@3202 3192 #endif /* USDT2 */
fparain@1759 3193
sla@5237 3194 EventThreadSleep event;
sla@5237 3195
duke@435 3196 if (millis == 0) {
duke@435 3197 // When ConvertSleepToYield is on, this matches the classic VM implementation of
duke@435 3198 // JVM_Sleep. Critical for similar threading behaviour (Win32)
duke@435 3199 // It appears that in certain GUI contexts, it may be beneficial to do a short sleep
duke@435 3200 // for SOLARIS
duke@435 3201 if (ConvertSleepToYield) {
duke@435 3202 os::yield();
duke@435 3203 } else {
duke@435 3204 ThreadState old_state = thread->osthread()->get_state();
duke@435 3205 thread->osthread()->set_state(SLEEPING);
duke@435 3206 os::sleep(thread, MinSleepInterval, false);
duke@435 3207 thread->osthread()->set_state(old_state);
duke@435 3208 }
duke@435 3209 } else {
duke@435 3210 ThreadState old_state = thread->osthread()->get_state();
duke@435 3211 thread->osthread()->set_state(SLEEPING);
duke@435 3212 if (os::sleep(thread, millis, true) == OS_INTRPT) {
duke@435 3213 // An asynchronous exception (e.g., ThreadDeathException) could have been thrown on
duke@435 3214 // us while we were sleeping. We do not overwrite those.
duke@435 3215 if (!HAS_PENDING_EXCEPTION) {
sla@5237 3216 if (event.should_commit()) {
sla@5237 3217 event.set_time(millis);
sla@5237 3218 event.commit();
sla@5237 3219 }
dcubed@3202 3220 #ifndef USDT2
fparain@1759 3221 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,1);
dcubed@3202 3222 #else /* USDT2 */
dcubed@3202 3223 HOTSPOT_THREAD_SLEEP_END(
dcubed@3202 3224 1);
dcubed@3202 3225 #endif /* USDT2 */
duke@435 3226 // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
duke@435 3227 // to properly restore the thread state. That's likely wrong.
duke@435 3228 THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
duke@435 3229 }
duke@435 3230 }
duke@435 3231 thread->osthread()->set_state(old_state);
duke@435 3232 }
sla@5237 3233 if (event.should_commit()) {
sla@5237 3234 event.set_time(millis);
sla@5237 3235 event.commit();
sla@5237 3236 }
dcubed@3202 3237 #ifndef USDT2
fparain@1759 3238 HS_DTRACE_PROBE1(hotspot, thread__sleep__end,0);
dcubed@3202 3239 #else /* USDT2 */
dcubed@3202 3240 HOTSPOT_THREAD_SLEEP_END(
dcubed@3202 3241 0);
dcubed@3202 3242 #endif /* USDT2 */
duke@435 3243 JVM_END
duke@435 3244
duke@435 3245 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
duke@435 3246 JVMWrapper("JVM_CurrentThread");
duke@435 3247 oop jthread = thread->threadObj();
duke@435 3248 assert (thread != NULL, "no current thread!");
duke@435 3249 return JNIHandles::make_local(env, jthread);
duke@435 3250 JVM_END
duke@435 3251
duke@435 3252
duke@435 3253 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread))
duke@435 3254 JVMWrapper("JVM_CountStackFrames");
duke@435 3255
duke@435 3256 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
duke@435 3257 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3258 bool throw_illegal_thread_state = false;
duke@435 3259 int count = 0;
duke@435 3260
duke@435 3261 {
duke@435 3262 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
duke@435 3263 // We need to re-resolve the java_thread, since a GC might have happened during the
duke@435 3264 // acquire of the lock
duke@435 3265 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
duke@435 3266
duke@435 3267 if (thr == NULL) {
duke@435 3268 // do nothing
duke@435 3269 } else if(! thr->is_external_suspend() || ! thr->frame_anchor()->walkable()) {
duke@435 3270 // Check whether this java thread has been suspended already. If not, throws
duke@435 3271 // IllegalThreadStateException. We defer to throw that exception until
duke@435 3272 // Threads_lock is released since loading exception class has to leave VM.
duke@435 3273 // The correct way to test a thread is actually suspended is
duke@435 3274 // wait_for_ext_suspend_completion(), but we can't call that while holding
duke@435 3275 // the Threads_lock. The above tests are sufficient for our purposes
duke@435 3276 // provided the walkability of the stack is stable - which it isn't
duke@435 3277 // 100% but close enough for most practical purposes.
duke@435 3278 throw_illegal_thread_state = true;
duke@435 3279 } else {
duke@435 3280 // Count all java activation, i.e., number of vframes
duke@435 3281 for(vframeStream vfst(thr); !vfst.at_end(); vfst.next()) {
duke@435 3282 // Native frames are not counted
duke@435 3283 if (!vfst.method()->is_native()) count++;
duke@435 3284 }
duke@435 3285 }
duke@435 3286 }
duke@435 3287
duke@435 3288 if (throw_illegal_thread_state) {
duke@435 3289 THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(),
duke@435 3290 "this thread is not suspended");
duke@435 3291 }
duke@435 3292 return count;
duke@435 3293 JVM_END
duke@435 3294
duke@435 3295 // Consider: A better way to implement JVM_Interrupt() is to acquire
duke@435 3296 // Threads_lock to resolve the jthread into a Thread pointer, fetch
duke@435 3297 // Thread->platformevent, Thread->native_thr, Thread->parker, etc.,
duke@435 3298 // drop Threads_lock, and the perform the unpark() and thr_kill() operations
duke@435 3299 // outside the critical section. Threads_lock is hot so we want to minimize
duke@435 3300 // the hold-time. A cleaner interface would be to decompose interrupt into
duke@435 3301 // two steps. The 1st phase, performed under Threads_lock, would return
duke@435 3302 // a closure that'd be invoked after Threads_lock was dropped.
duke@435 3303 // This tactic is safe as PlatformEvent and Parkers are type-stable (TSM) and
duke@435 3304 // admit spurious wakeups.
duke@435 3305
duke@435 3306 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
duke@435 3307 JVMWrapper("JVM_Interrupt");
duke@435 3308
duke@435 3309 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
duke@435 3310 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3311 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
duke@435 3312 // We need to re-resolve the java_thread, since a GC might have happened during the
duke@435 3313 // acquire of the lock
duke@435 3314 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
duke@435 3315 if (thr != NULL) {
duke@435 3316 Thread::interrupt(thr);
duke@435 3317 }
duke@435 3318 JVM_END
duke@435 3319
duke@435 3320
duke@435 3321 JVM_QUICK_ENTRY(jboolean, JVM_IsInterrupted(JNIEnv* env, jobject jthread, jboolean clear_interrupted))
duke@435 3322 JVMWrapper("JVM_IsInterrupted");
duke@435 3323
duke@435 3324 // Ensure that the C++ Thread and OSThread structures aren't freed before we operate
duke@435 3325 oop java_thread = JNIHandles::resolve_non_null(jthread);
duke@435 3326 MutexLockerEx ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
duke@435 3327 // We need to re-resolve the java_thread, since a GC might have happened during the
duke@435 3328 // acquire of the lock
duke@435 3329 JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
duke@435 3330 if (thr == NULL) {
duke@435 3331 return JNI_FALSE;
duke@435 3332 } else {
duke@435 3333 return (jboolean) Thread::is_interrupted(thr, clear_interrupted != 0);
duke@435 3334 }
duke@435 3335 JVM_END
duke@435 3336
duke@435 3337
duke@435 3338 // Return true iff the current thread has locked the object passed in
duke@435 3339
duke@435 3340 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
duke@435 3341 JVMWrapper("JVM_HoldsLock");
duke@435 3342 assert(THREAD->is_Java_thread(), "sanity check");
duke@435 3343 if (obj == NULL) {
duke@435 3344 THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
duke@435 3345 }
duke@435 3346 Handle h_obj(THREAD, JNIHandles::resolve(obj));
duke@435 3347 return ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, h_obj);
duke@435 3348 JVM_END
duke@435 3349
duke@435 3350
duke@435 3351 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
duke@435 3352 JVMWrapper("JVM_DumpAllStacks");
duke@435 3353 VM_PrintThreads op;
duke@435 3354 VMThread::execute(&op);
duke@435 3355 if (JvmtiExport::should_post_data_dump()) {
duke@435 3356 JvmtiExport::post_data_dump();
duke@435 3357 }
duke@435 3358 JVM_END
duke@435 3359
dcubed@3202 3360 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
dcubed@3202 3361 JVMWrapper("JVM_SetNativeThreadName");
dcubed@3202 3362 ResourceMark rm(THREAD);
dcubed@3202 3363 oop java_thread = JNIHandles::resolve_non_null(jthread);
dcubed@3202 3364 JavaThread* thr = java_lang_Thread::thread(java_thread);
dcubed@3202 3365 // Thread naming only supported for the current thread, doesn't work for
dcubed@3202 3366 // target threads.
dcubed@3202 3367 if (Thread::current() == thr && !thr->has_attached_via_jni()) {
dcubed@3202 3368 // we don't set the name of an attached thread to avoid stepping
dcubed@3202 3369 // on other programs
dcubed@3202 3370 const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
dcubed@3202 3371 os::set_native_thread_name(thread_name);
dcubed@3202 3372 }
dcubed@3202 3373 JVM_END
duke@435 3374
duke@435 3375 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
duke@435 3376
duke@435 3377 static bool is_trusted_frame(JavaThread* jthread, vframeStream* vfst) {
duke@435 3378 assert(jthread->is_Java_thread(), "must be a Java thread");
duke@435 3379 if (jthread->privileged_stack_top() == NULL) return false;
duke@435 3380 if (jthread->privileged_stack_top()->frame_id() == vfst->frame_id()) {
duke@435 3381 oop loader = jthread->privileged_stack_top()->class_loader();
duke@435 3382 if (loader == NULL) return true;
duke@435 3383 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader);
duke@435 3384 if (trusted) return true;
duke@435 3385 }
duke@435 3386 return false;
duke@435 3387 }
duke@435 3388
duke@435 3389 JVM_ENTRY(jclass, JVM_CurrentLoadedClass(JNIEnv *env))
duke@435 3390 JVMWrapper("JVM_CurrentLoadedClass");
duke@435 3391 ResourceMark rm(THREAD);
duke@435 3392
duke@435 3393 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
duke@435 3394 // if a method in a class in a trusted loader is in a doPrivileged, return NULL
duke@435 3395 bool trusted = is_trusted_frame(thread, &vfst);
duke@435 3396 if (trusted) return NULL;
duke@435 3397
coleenp@4037 3398 Method* m = vfst.method();
duke@435 3399 if (!m->is_native()) {
coleenp@4251 3400 InstanceKlass* holder = m->method_holder();
coleenp@4251 3401 oop loader = holder->class_loader();
duke@435 3402 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
coleenp@4251 3403 return (jclass) JNIHandles::make_local(env, holder->java_mirror());
duke@435 3404 }
duke@435 3405 }
duke@435 3406 }
duke@435 3407 return NULL;
duke@435 3408 JVM_END
duke@435 3409
duke@435 3410
duke@435 3411 JVM_ENTRY(jobject, JVM_CurrentClassLoader(JNIEnv *env))
duke@435 3412 JVMWrapper("JVM_CurrentClassLoader");
duke@435 3413 ResourceMark rm(THREAD);
duke@435 3414
duke@435 3415 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
duke@435 3416
duke@435 3417 // if a method in a class in a trusted loader is in a doPrivileged, return NULL
duke@435 3418 bool trusted = is_trusted_frame(thread, &vfst);
duke@435 3419 if (trusted) return NULL;
duke@435 3420
coleenp@4037 3421 Method* m = vfst.method();
duke@435 3422 if (!m->is_native()) {
coleenp@4251 3423 InstanceKlass* holder = m->method_holder();
duke@435 3424 assert(holder->is_klass(), "just checking");
coleenp@4251 3425 oop loader = holder->class_loader();
duke@435 3426 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
duke@435 3427 return JNIHandles::make_local(env, loader);
duke@435 3428 }
duke@435 3429 }
duke@435 3430 }
duke@435 3431 return NULL;
duke@435 3432 JVM_END
duke@435 3433
duke@435 3434
duke@435 3435 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
duke@435 3436 JVMWrapper("JVM_GetClassContext");
duke@435 3437 ResourceMark rm(THREAD);
duke@435 3438 JvmtiVMObjectAllocEventCollector oam;
twisti@4866 3439 vframeStream vfst(thread);
twisti@4866 3440
twisti@4866 3441 if (SystemDictionary::reflect_CallerSensitive_klass() != NULL) {
twisti@4866 3442 // This must only be called from SecurityManager.getClassContext
twisti@4866 3443 Method* m = vfst.method();
twisti@4866 3444 if (!(m->method_holder() == SystemDictionary::SecurityManager_klass() &&
twisti@4866 3445 m->name() == vmSymbols::getClassContext_name() &&
twisti@4866 3446 m->signature() == vmSymbols::void_class_array_signature())) {
twisti@4866 3447 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
twisti@4866 3448 }
twisti@4866 3449 }
twisti@4866 3450
twisti@4866 3451 // Collect method holders
drchase@5287 3452 GrowableArray<KlassHandle>* klass_array = new GrowableArray<KlassHandle>();
twisti@4866 3453 for (; !vfst.at_end(); vfst.security_next()) {
twisti@4866 3454 Method* m = vfst.method();
duke@435 3455 // Native frames are not returned
twisti@4866 3456 if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) {
twisti@4866 3457 Klass* holder = m->method_holder();
duke@435 3458 assert(holder->is_klass(), "just checking");
drchase@5287 3459 klass_array->append(holder);
duke@435 3460 }
duke@435 3461 }
duke@435 3462
duke@435 3463 // Create result array of type [Ljava/lang/Class;
drchase@5287 3464 objArrayOop result = oopFactory::new_objArray(SystemDictionary::Class_klass(), klass_array->length(), CHECK_NULL);
duke@435 3465 // Fill in mirrors corresponding to method holders
drchase@5287 3466 for (int i = 0; i < klass_array->length(); i++) {
drchase@5287 3467 result->obj_at_put(i, klass_array->at(i)->java_mirror());
duke@435 3468 }
duke@435 3469
duke@435 3470 return (jobjectArray) JNIHandles::make_local(env, result);
duke@435 3471 JVM_END
duke@435 3472
duke@435 3473
duke@435 3474 JVM_ENTRY(jint, JVM_ClassDepth(JNIEnv *env, jstring name))
duke@435 3475 JVMWrapper("JVM_ClassDepth");
duke@435 3476 ResourceMark rm(THREAD);
duke@435 3477 Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
duke@435 3478 Handle class_name_str = java_lang_String::internalize_classname(h_name, CHECK_0);
duke@435 3479
duke@435 3480 const char* str = java_lang_String::as_utf8_string(class_name_str());
coleenp@2497 3481 TempNewSymbol class_name_sym = SymbolTable::probe(str, (int)strlen(str));
coleenp@2497 3482 if (class_name_sym == NULL) {
duke@435 3483 return -1;
duke@435 3484 }
duke@435 3485
duke@435 3486 int depth = 0;
duke@435 3487
duke@435 3488 for(vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
duke@435 3489 if (!vfst.method()->is_native()) {
coleenp@4251 3490 InstanceKlass* holder = vfst.method()->method_holder();
duke@435 3491 assert(holder->is_klass(), "just checking");
coleenp@4251 3492 if (holder->name() == class_name_sym) {
duke@435 3493 return depth;
duke@435 3494 }
duke@435 3495 depth++;
duke@435 3496 }
duke@435 3497 }
duke@435 3498 return -1;
duke@435 3499 JVM_END
duke@435 3500
duke@435 3501
duke@435 3502 JVM_ENTRY(jint, JVM_ClassLoaderDepth(JNIEnv *env))
duke@435 3503 JVMWrapper("JVM_ClassLoaderDepth");
duke@435 3504 ResourceMark rm(THREAD);
duke@435 3505 int depth = 0;
duke@435 3506 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
duke@435 3507 // if a method in a class in a trusted loader is in a doPrivileged, return -1
duke@435 3508 bool trusted = is_trusted_frame(thread, &vfst);
duke@435 3509 if (trusted) return -1;
duke@435 3510
coleenp@4037 3511 Method* m = vfst.method();
duke@435 3512 if (!m->is_native()) {
coleenp@4251 3513 InstanceKlass* holder = m->method_holder();
duke@435 3514 assert(holder->is_klass(), "just checking");
coleenp@4251 3515 oop loader = holder->class_loader();
duke@435 3516 if (loader != NULL && !java_lang_ClassLoader::is_trusted_loader(loader)) {
duke@435 3517 return depth;
duke@435 3518 }
duke@435 3519 depth++;
duke@435 3520 }
duke@435 3521 }
duke@435 3522 return -1;
duke@435 3523 JVM_END
duke@435 3524
duke@435 3525
duke@435 3526 // java.lang.Package ////////////////////////////////////////////////////////////////
duke@435 3527
duke@435 3528
duke@435 3529 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
duke@435 3530 JVMWrapper("JVM_GetSystemPackage");
duke@435 3531 ResourceMark rm(THREAD);
duke@435 3532 JvmtiVMObjectAllocEventCollector oam;
duke@435 3533 char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
duke@435 3534 oop result = ClassLoader::get_system_package(str, CHECK_NULL);
duke@435 3535 return (jstring) JNIHandles::make_local(result);
duke@435 3536 JVM_END
duke@435 3537
duke@435 3538
duke@435 3539 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
duke@435 3540 JVMWrapper("JVM_GetSystemPackages");
duke@435 3541 JvmtiVMObjectAllocEventCollector oam;
duke@435 3542 objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
duke@435 3543 return (jobjectArray) JNIHandles::make_local(result);
duke@435 3544 JVM_END
duke@435 3545
duke@435 3546
duke@435 3547 // ObjectInputStream ///////////////////////////////////////////////////////////////
duke@435 3548
coleenp@4037 3549 bool force_verify_field_access(Klass* current_class, Klass* field_class, AccessFlags access, bool classloader_only) {
duke@435 3550 if (current_class == NULL) {
duke@435 3551 return true;
duke@435 3552 }
duke@435 3553 if ((current_class == field_class) || access.is_public()) {
duke@435 3554 return true;
duke@435 3555 }
duke@435 3556
duke@435 3557 if (access.is_protected()) {
duke@435 3558 // See if current_class is a subclass of field_class
hseigel@4278 3559 if (current_class->is_subclass_of(field_class)) {
duke@435 3560 return true;
duke@435 3561 }
duke@435 3562 }
duke@435 3563
coleenp@4037 3564 return (!access.is_private() && InstanceKlass::cast(current_class)->is_same_class_package(field_class));
duke@435 3565 }
duke@435 3566
duke@435 3567
duke@435 3568 // JVM_AllocateNewObject and JVM_AllocateNewArray are unused as of 1.4
duke@435 3569 JVM_ENTRY(jobject, JVM_AllocateNewObject(JNIEnv *env, jobject receiver, jclass currClass, jclass initClass))
duke@435 3570 JVMWrapper("JVM_AllocateNewObject");
duke@435 3571 JvmtiVMObjectAllocEventCollector oam;
duke@435 3572 // Receiver is not used
duke@435 3573 oop curr_mirror = JNIHandles::resolve_non_null(currClass);
duke@435 3574 oop init_mirror = JNIHandles::resolve_non_null(initClass);
duke@435 3575
duke@435 3576 // Cannot instantiate primitive types
duke@435 3577 if (java_lang_Class::is_primitive(curr_mirror) || java_lang_Class::is_primitive(init_mirror)) {
duke@435 3578 ResourceMark rm(THREAD);
duke@435 3579 THROW_0(vmSymbols::java_lang_InvalidClassException());
duke@435 3580 }
duke@435 3581
duke@435 3582 // Arrays not allowed here, must use JVM_AllocateNewArray
hseigel@4278 3583 if (java_lang_Class::as_Klass(curr_mirror)->oop_is_array() ||
hseigel@4278 3584 java_lang_Class::as_Klass(init_mirror)->oop_is_array()) {
duke@435 3585 ResourceMark rm(THREAD);
duke@435 3586 THROW_0(vmSymbols::java_lang_InvalidClassException());
duke@435 3587 }
duke@435 3588
coleenp@4037 3589 instanceKlassHandle curr_klass (THREAD, java_lang_Class::as_Klass(curr_mirror));
coleenp@4037 3590 instanceKlassHandle init_klass (THREAD, java_lang_Class::as_Klass(init_mirror));
duke@435 3591
duke@435 3592 assert(curr_klass->is_subclass_of(init_klass()), "just checking");
duke@435 3593
duke@435 3594 // Interfaces, abstract classes, and java.lang.Class classes cannot be instantiated directly.
duke@435 3595 curr_klass->check_valid_for_instantiation(false, CHECK_NULL);
duke@435 3596
duke@435 3597 // Make sure klass is initialized, since we are about to instantiate one of them.
duke@435 3598 curr_klass->initialize(CHECK_NULL);
duke@435 3599
duke@435 3600 methodHandle m (THREAD,
duke@435 3601 init_klass->find_method(vmSymbols::object_initializer_name(),
duke@435 3602 vmSymbols::void_method_signature()));
duke@435 3603 if (m.is_null()) {
duke@435 3604 ResourceMark rm(THREAD);
duke@435 3605 THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(),
hseigel@4278 3606 Method::name_and_sig_as_C_string(init_klass(),
duke@435 3607 vmSymbols::object_initializer_name(),
duke@435 3608 vmSymbols::void_method_signature()));
duke@435 3609 }
duke@435 3610
duke@435 3611 if (curr_klass == init_klass && !m->is_public()) {
duke@435 3612 // Calling the constructor for class 'curr_klass'.
duke@435 3613 // Only allow calls to a public no-arg constructor.
duke@435 3614 // This path corresponds to creating an Externalizable object.
duke@435 3615 THROW_0(vmSymbols::java_lang_IllegalAccessException());
duke@435 3616 }
duke@435 3617
duke@435 3618 if (!force_verify_field_access(curr_klass(), init_klass(), m->access_flags(), false)) {
duke@435 3619 // subclass 'curr_klass' does not have access to no-arg constructor of 'initcb'
duke@435 3620 THROW_0(vmSymbols::java_lang_IllegalAccessException());
duke@435 3621 }
duke@435 3622
duke@435 3623 Handle obj = curr_klass->allocate_instance_handle(CHECK_NULL);
duke@435 3624 // Call constructor m. This might call a constructor higher up in the hierachy
duke@435 3625 JavaCalls::call_default_constructor(thread, m, obj, CHECK_NULL);
duke@435 3626
duke@435 3627 return JNIHandles::make_local(obj());
duke@435 3628 JVM_END
duke@435 3629
duke@435 3630
duke@435 3631 JVM_ENTRY(jobject, JVM_AllocateNewArray(JNIEnv *env, jobject obj, jclass currClass, jint length))
duke@435 3632 JVMWrapper("JVM_AllocateNewArray");
duke@435 3633 JvmtiVMObjectAllocEventCollector oam;
duke@435 3634 oop mirror = JNIHandles::resolve_non_null(currClass);
duke@435 3635
duke@435 3636 if (java_lang_Class::is_primitive(mirror)) {
duke@435 3637 THROW_0(vmSymbols::java_lang_InvalidClassException());
duke@435 3638 }
coleenp@4037 3639 Klass* k = java_lang_Class::as_Klass(mirror);
duke@435 3640 oop result;
duke@435 3641
coleenp@4037 3642 if (k->oop_is_typeArray()) {
duke@435 3643 // typeArray
coleenp@4142 3644 result = TypeArrayKlass::cast(k)->allocate(length, CHECK_NULL);
coleenp@4037 3645 } else if (k->oop_is_objArray()) {
duke@435 3646 // objArray
coleenp@4142 3647 ObjArrayKlass* oak = ObjArrayKlass::cast(k);
duke@435 3648 oak->initialize(CHECK_NULL); // make sure class is initialized (matches Classic VM behavior)
duke@435 3649 result = oak->allocate(length, CHECK_NULL);
duke@435 3650 } else {
duke@435 3651 THROW_0(vmSymbols::java_lang_InvalidClassException());
duke@435 3652 }
duke@435 3653 return JNIHandles::make_local(env, result);
duke@435 3654 JVM_END
duke@435 3655
duke@435 3656
duke@435 3657 // Return the first non-null class loader up the execution stack, or null
duke@435 3658 // if only code from the null class loader is on the stack.
duke@435 3659
duke@435 3660 JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
duke@435 3661 for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
duke@435 3662 // UseNewReflection
duke@435 3663 vfst.skip_reflection_related_frames(); // Only needed for 1.4 reflection
coleenp@4251 3664 oop loader = vfst.method()->method_holder()->class_loader();
duke@435 3665 if (loader != NULL) {
duke@435 3666 return JNIHandles::make_local(env, loader);
duke@435 3667 }
duke@435 3668 }
duke@435 3669 return NULL;
duke@435 3670 JVM_END
duke@435 3671
duke@435 3672
duke@435 3673 // Load a class relative to the most recent class on the stack with a non-null
duke@435 3674 // classloader.
duke@435 3675 // This function has been deprecated and should not be considered part of the
duke@435 3676 // specified JVM interface.
duke@435 3677
duke@435 3678 JVM_ENTRY(jclass, JVM_LoadClass0(JNIEnv *env, jobject receiver,
duke@435 3679 jclass currClass, jstring currClassName))
duke@435 3680 JVMWrapper("JVM_LoadClass0");
duke@435 3681 // Receiver is not used
duke@435 3682 ResourceMark rm(THREAD);
duke@435 3683
duke@435 3684 // Class name argument is not guaranteed to be in internal format
duke@435 3685 Handle classname (THREAD, JNIHandles::resolve_non_null(currClassName));
duke@435 3686 Handle string = java_lang_String::internalize_classname(classname, CHECK_NULL);
duke@435 3687
duke@435 3688 const char* str = java_lang_String::as_utf8_string(string());
duke@435 3689
coleenp@2497 3690 if (str == NULL || (int)strlen(str) > Symbol::max_length()) {
duke@435 3691 // It's impossible to create this class; the name cannot fit
duke@435 3692 // into the constant pool.
duke@435 3693 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), str);
duke@435 3694 }
duke@435 3695
coleenp@2497 3696 TempNewSymbol name = SymbolTable::new_symbol(str, CHECK_NULL);
duke@435 3697 Handle curr_klass (THREAD, JNIHandles::resolve(currClass));
duke@435 3698 // Find the most recent class on the stack with a non-null classloader
duke@435 3699 oop loader = NULL;
duke@435 3700 oop protection_domain = NULL;
duke@435 3701 if (curr_klass.is_null()) {
duke@435 3702 for (vframeStream vfst(thread);
duke@435 3703 !vfst.at_end() && loader == NULL;
duke@435 3704 vfst.next()) {
duke@435 3705 if (!vfst.method()->is_native()) {
coleenp@4251 3706 InstanceKlass* holder = vfst.method()->method_holder();
coleenp@4251 3707 loader = holder->class_loader();
coleenp@4251 3708 protection_domain = holder->protection_domain();
duke@435 3709 }
duke@435 3710 }
duke@435 3711 } else {
coleenp@4037 3712 Klass* curr_klass_oop = java_lang_Class::as_Klass(curr_klass());
coleenp@4037 3713 loader = InstanceKlass::cast(curr_klass_oop)->class_loader();
coleenp@4037 3714 protection_domain = InstanceKlass::cast(curr_klass_oop)->protection_domain();
duke@435 3715 }
duke@435 3716 Handle h_loader(THREAD, loader);
duke@435 3717 Handle h_prot (THREAD, protection_domain);
acorn@1092 3718 jclass result = find_class_from_class_loader(env, name, true, h_loader, h_prot,
acorn@1092 3719 false, thread);
acorn@1092 3720 if (TraceClassResolution && result != NULL) {
coleenp@4037 3721 trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
acorn@1092 3722 }
acorn@1092 3723 return result;
duke@435 3724 JVM_END
duke@435 3725
duke@435 3726
duke@435 3727 // Array ///////////////////////////////////////////////////////////////////////////////////////////
duke@435 3728
duke@435 3729
duke@435 3730 // resolve array handle and check arguments
duke@435 3731 static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) {
duke@435 3732 if (arr == NULL) {
duke@435 3733 THROW_0(vmSymbols::java_lang_NullPointerException());
duke@435 3734 }
duke@435 3735 oop a = JNIHandles::resolve_non_null(arr);
coleenp@4037 3736 if (!a->is_array() || (type_array_only && !a->is_typeArray())) {
duke@435 3737 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array");
duke@435 3738 }
duke@435 3739 return arrayOop(a);
duke@435 3740 }
duke@435 3741
duke@435 3742
duke@435 3743 JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr))
duke@435 3744 JVMWrapper("JVM_GetArrayLength");
duke@435 3745 arrayOop a = check_array(env, arr, false, CHECK_0);
duke@435 3746 return a->length();
duke@435 3747 JVM_END
duke@435 3748
duke@435 3749
duke@435 3750 JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index))
duke@435 3751 JVMWrapper("JVM_Array_Get");
duke@435 3752 JvmtiVMObjectAllocEventCollector oam;
duke@435 3753 arrayOop a = check_array(env, arr, false, CHECK_NULL);
duke@435 3754 jvalue value;
duke@435 3755 BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL);
duke@435 3756 oop box = Reflection::box(&value, type, CHECK_NULL);
duke@435 3757 return JNIHandles::make_local(env, box);
duke@435 3758 JVM_END
duke@435 3759
duke@435 3760
duke@435 3761 JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode))
duke@435 3762 JVMWrapper("JVM_GetPrimitiveArrayElement");
duke@435 3763 jvalue value;
duke@435 3764 value.i = 0; // to initialize value before getting used in CHECK
duke@435 3765 arrayOop a = check_array(env, arr, true, CHECK_(value));
duke@435 3766 assert(a->is_typeArray(), "just checking");
duke@435 3767 BasicType type = Reflection::array_get(&value, a, index, CHECK_(value));
duke@435 3768 BasicType wide_type = (BasicType) wCode;
duke@435 3769 if (type != wide_type) {
duke@435 3770 Reflection::widen(&value, type, wide_type, CHECK_(value));
duke@435 3771 }
duke@435 3772 return value;
duke@435 3773 JVM_END
duke@435 3774
duke@435 3775
duke@435 3776 JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val))
duke@435 3777 JVMWrapper("JVM_SetArrayElement");
duke@435 3778 arrayOop a = check_array(env, arr, false, CHECK);
duke@435 3779 oop box = JNIHandles::resolve(val);
duke@435 3780 jvalue value;
duke@435 3781 value.i = 0; // to initialize value before getting used in CHECK
duke@435 3782 BasicType value_type;
duke@435 3783 if (a->is_objArray()) {
duke@435 3784 // Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array
duke@435 3785 value_type = Reflection::unbox_for_regular_object(box, &value);
duke@435 3786 } else {
duke@435 3787 value_type = Reflection::unbox_for_primitive(box, &value, CHECK);
duke@435 3788 }
duke@435 3789 Reflection::array_set(&value, a, index, value_type, CHECK);
duke@435 3790 JVM_END
duke@435 3791
duke@435 3792
duke@435 3793 JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode))
duke@435 3794 JVMWrapper("JVM_SetPrimitiveArrayElement");
duke@435 3795 arrayOop a = check_array(env, arr, true, CHECK);
duke@435 3796 assert(a->is_typeArray(), "just checking");
duke@435 3797 BasicType value_type = (BasicType) vCode;
duke@435 3798 Reflection::array_set(&v, a, index, value_type, CHECK);
duke@435 3799 JVM_END
duke@435 3800
duke@435 3801
duke@435 3802 JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length))
duke@435 3803 JVMWrapper("JVM_NewArray");
duke@435 3804 JvmtiVMObjectAllocEventCollector oam;
duke@435 3805 oop element_mirror = JNIHandles::resolve(eltClass);
duke@435 3806 oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL);
duke@435 3807 return JNIHandles::make_local(env, result);
duke@435 3808 JVM_END
duke@435 3809
duke@435 3810
duke@435 3811 JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim))
duke@435 3812 JVMWrapper("JVM_NewMultiArray");
duke@435 3813 JvmtiVMObjectAllocEventCollector oam;
duke@435 3814 arrayOop dim_array = check_array(env, dim, true, CHECK_NULL);
duke@435 3815 oop element_mirror = JNIHandles::resolve(eltClass);
duke@435 3816 assert(dim_array->is_typeArray(), "just checking");
duke@435 3817 oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL);
duke@435 3818 return JNIHandles::make_local(env, result);
duke@435 3819 JVM_END
duke@435 3820
duke@435 3821
duke@435 3822 // Networking library support ////////////////////////////////////////////////////////////////////
duke@435 3823
duke@435 3824 JVM_LEAF(jint, JVM_InitializeSocketLibrary())
duke@435 3825 JVMWrapper("JVM_InitializeSocketLibrary");
ikrylov@2322 3826 return 0;
duke@435 3827 JVM_END
duke@435 3828
duke@435 3829
duke@435 3830 JVM_LEAF(jint, JVM_Socket(jint domain, jint type, jint protocol))
duke@435 3831 JVMWrapper("JVM_Socket");
ikrylov@2322 3832 return os::socket(domain, type, protocol);
duke@435 3833 JVM_END
duke@435 3834
duke@435 3835
duke@435 3836 JVM_LEAF(jint, JVM_SocketClose(jint fd))
duke@435 3837 JVMWrapper2("JVM_SocketClose (0x%x)", fd);
duke@435 3838 //%note jvm_r6
ikrylov@2322 3839 return os::socket_close(fd);
duke@435 3840 JVM_END
duke@435 3841
duke@435 3842
duke@435 3843 JVM_LEAF(jint, JVM_SocketShutdown(jint fd, jint howto))
duke@435 3844 JVMWrapper2("JVM_SocketShutdown (0x%x)", fd);
duke@435 3845 //%note jvm_r6
ikrylov@2322 3846 return os::socket_shutdown(fd, howto);
duke@435 3847 JVM_END
duke@435 3848
duke@435 3849
duke@435 3850 JVM_LEAF(jint, JVM_Recv(jint fd, char *buf, jint nBytes, jint flags))
duke@435 3851 JVMWrapper2("JVM_Recv (0x%x)", fd);
duke@435 3852 //%note jvm_r6
phh@3344 3853 return os::recv(fd, buf, (size_t)nBytes, (uint)flags);
duke@435 3854 JVM_END
duke@435 3855
duke@435 3856
duke@435 3857 JVM_LEAF(jint, JVM_Send(jint fd, char *buf, jint nBytes, jint flags))
duke@435 3858 JVMWrapper2("JVM_Send (0x%x)", fd);
duke@435 3859 //%note jvm_r6
phh@3344 3860 return os::send(fd, buf, (size_t)nBytes, (uint)flags);
duke@435 3861 JVM_END
duke@435 3862
duke@435 3863
duke@435 3864 JVM_LEAF(jint, JVM_Timeout(int fd, long timeout))
duke@435 3865 JVMWrapper2("JVM_Timeout (0x%x)", fd);
duke@435 3866 //%note jvm_r6
ikrylov@2322 3867 return os::timeout(fd, timeout);
duke@435 3868 JVM_END
duke@435 3869
duke@435 3870
duke@435 3871 JVM_LEAF(jint, JVM_Listen(jint fd, jint count))
duke@435 3872 JVMWrapper2("JVM_Listen (0x%x)", fd);
duke@435 3873 //%note jvm_r6
ikrylov@2322 3874 return os::listen(fd, count);
duke@435 3875 JVM_END
duke@435 3876
duke@435 3877
duke@435 3878 JVM_LEAF(jint, JVM_Connect(jint fd, struct sockaddr *him, jint len))
duke@435 3879 JVMWrapper2("JVM_Connect (0x%x)", fd);
duke@435 3880 //%note jvm_r6
phh@3344 3881 return os::connect(fd, him, (socklen_t)len);
duke@435 3882 JVM_END
duke@435 3883
duke@435 3884
duke@435 3885 JVM_LEAF(jint, JVM_Bind(jint fd, struct sockaddr *him, jint len))
duke@435 3886 JVMWrapper2("JVM_Bind (0x%x)", fd);
duke@435 3887 //%note jvm_r6
phh@3344 3888 return os::bind(fd, him, (socklen_t)len);
duke@435 3889 JVM_END
duke@435 3890
duke@435 3891
duke@435 3892 JVM_LEAF(jint, JVM_Accept(jint fd, struct sockaddr *him, jint *len))
duke@435 3893 JVMWrapper2("JVM_Accept (0x%x)", fd);
duke@435 3894 //%note jvm_r6
phh@3344 3895 socklen_t socklen = (socklen_t)(*len);
phh@3344 3896 jint result = os::accept(fd, him, &socklen);
phh@3344 3897 *len = (jint)socklen;
phh@3344 3898 return result;
duke@435 3899 JVM_END
duke@435 3900
duke@435 3901
duke@435 3902 JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen))
duke@435 3903 JVMWrapper2("JVM_RecvFrom (0x%x)", fd);
duke@435 3904 //%note jvm_r6
phh@3344 3905 socklen_t socklen = (socklen_t)(*fromlen);
phh@3344 3906 jint result = os::recvfrom(fd, buf, (size_t)nBytes, (uint)flags, from, &socklen);
phh@3344 3907 *fromlen = (int)socklen;
phh@3344 3908 return result;
duke@435 3909 JVM_END
duke@435 3910
duke@435 3911
duke@435 3912 JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len))
duke@435 3913 JVMWrapper2("JVM_GetSockName (0x%x)", fd);
duke@435 3914 //%note jvm_r6
phh@3344 3915 socklen_t socklen = (socklen_t)(*len);
phh@3344 3916 jint result = os::get_sock_name(fd, him, &socklen);
phh@3344 3917 *len = (int)socklen;
phh@3344 3918 return result;
duke@435 3919 JVM_END
duke@435 3920
duke@435 3921
duke@435 3922 JVM_LEAF(jint, JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen))
duke@435 3923 JVMWrapper2("JVM_SendTo (0x%x)", fd);
duke@435 3924 //%note jvm_r6
phh@3344 3925 return os::sendto(fd, buf, (size_t)len, (uint)flags, to, (socklen_t)tolen);
duke@435 3926 JVM_END
duke@435 3927
duke@435 3928
duke@435 3929 JVM_LEAF(jint, JVM_SocketAvailable(jint fd, jint *pbytes))
duke@435 3930 JVMWrapper2("JVM_SocketAvailable (0x%x)", fd);
duke@435 3931 //%note jvm_r6
ikrylov@2322 3932 return os::socket_available(fd, pbytes);
duke@435 3933 JVM_END
duke@435 3934
duke@435 3935
duke@435 3936 JVM_LEAF(jint, JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen))
duke@435 3937 JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
duke@435 3938 //%note jvm_r6
phh@3344 3939 socklen_t socklen = (socklen_t)(*optlen);
phh@3344 3940 jint result = os::get_sock_opt(fd, level, optname, optval, &socklen);
phh@3344 3941 *optlen = (int)socklen;
phh@3344 3942 return result;
duke@435 3943 JVM_END
duke@435 3944
duke@435 3945
duke@435 3946 JVM_LEAF(jint, JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen))
duke@435 3947 JVMWrapper2("JVM_GetSockOpt (0x%x)", fd);
duke@435 3948 //%note jvm_r6
phh@3344 3949 return os::set_sock_opt(fd, level, optname, optval, (socklen_t)optlen);
duke@435 3950 JVM_END
duke@435 3951
phh@3344 3952
duke@435 3953 JVM_LEAF(int, JVM_GetHostName(char* name, int namelen))
duke@435 3954 JVMWrapper("JVM_GetHostName");
ikrylov@2322 3955 return os::get_host_name(name, namelen);
ikrylov@2322 3956 JVM_END
duke@435 3957
phh@3344 3958
duke@435 3959 // Library support ///////////////////////////////////////////////////////////////////////////
duke@435 3960
duke@435 3961 JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name))
duke@435 3962 //%note jvm_ct
duke@435 3963 JVMWrapper2("JVM_LoadLibrary (%s)", name);
duke@435 3964 char ebuf[1024];
duke@435 3965 void *load_result;
duke@435 3966 {
duke@435 3967 ThreadToNativeFromVM ttnfvm(thread);
ikrylov@2322 3968 load_result = os::dll_load(name, ebuf, sizeof ebuf);
duke@435 3969 }
duke@435 3970 if (load_result == NULL) {
duke@435 3971 char msg[1024];
duke@435 3972 jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf);
duke@435 3973 // Since 'ebuf' may contain a string encoded using
duke@435 3974 // platform encoding scheme, we need to pass
duke@435 3975 // Exceptions::unsafe_to_utf8 to the new_exception method
duke@435 3976 // as the last argument. See bug 6367357.
duke@435 3977 Handle h_exception =
duke@435 3978 Exceptions::new_exception(thread,
duke@435 3979 vmSymbols::java_lang_UnsatisfiedLinkError(),
duke@435 3980 msg, Exceptions::unsafe_to_utf8);
duke@435 3981
duke@435 3982 THROW_HANDLE_0(h_exception);
duke@435 3983 }
duke@435 3984 return load_result;
duke@435 3985 JVM_END
duke@435 3986
duke@435 3987
duke@435 3988 JVM_LEAF(void, JVM_UnloadLibrary(void* handle))
duke@435 3989 JVMWrapper("JVM_UnloadLibrary");
ikrylov@2322 3990 os::dll_unload(handle);
duke@435 3991 JVM_END
duke@435 3992
duke@435 3993
duke@435 3994 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
duke@435 3995 JVMWrapper2("JVM_FindLibraryEntry (%s)", name);
ikrylov@2322 3996 return os::dll_lookup(handle, name);
duke@435 3997 JVM_END
duke@435 3998
phh@3344 3999
duke@435 4000 // Floating point support ////////////////////////////////////////////////////////////////////
duke@435 4001
duke@435 4002 JVM_LEAF(jboolean, JVM_IsNaN(jdouble a))
duke@435 4003 JVMWrapper("JVM_IsNaN");
duke@435 4004 return g_isnan(a);
duke@435 4005 JVM_END
duke@435 4006
duke@435 4007
duke@435 4008 // JNI version ///////////////////////////////////////////////////////////////////////////////
duke@435 4009
duke@435 4010 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
duke@435 4011 JVMWrapper2("JVM_IsSupportedJNIVersion (%d)", version);
duke@435 4012 return Threads::is_supported_jni_version_including_1_1(version);
duke@435 4013 JVM_END
duke@435 4014
duke@435 4015
duke@435 4016 // String support ///////////////////////////////////////////////////////////////////////////
duke@435 4017
duke@435 4018 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
duke@435 4019 JVMWrapper("JVM_InternString");
duke@435 4020 JvmtiVMObjectAllocEventCollector oam;
duke@435 4021 if (str == NULL) return NULL;
duke@435 4022 oop string = JNIHandles::resolve_non_null(str);
duke@435 4023 oop result = StringTable::intern(string, CHECK_NULL);
duke@435 4024 return (jstring) JNIHandles::make_local(env, result);
duke@435 4025 JVM_END
duke@435 4026
duke@435 4027
duke@435 4028 // Raw monitor support //////////////////////////////////////////////////////////////////////
duke@435 4029
duke@435 4030 // The lock routine below calls lock_without_safepoint_check in order to get a raw lock
duke@435 4031 // without interfering with the safepoint mechanism. The routines are not JVM_LEAF because
duke@435 4032 // they might be called by non-java threads. The JVM_LEAF installs a NoHandleMark check
duke@435 4033 // that only works with java threads.
duke@435 4034
duke@435 4035
duke@435 4036 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
duke@435 4037 VM_Exit::block_if_vm_exited();
duke@435 4038 JVMWrapper("JVM_RawMonitorCreate");
duke@435 4039 return new Mutex(Mutex::native, "JVM_RawMonitorCreate");
duke@435 4040 }
duke@435 4041
duke@435 4042
duke@435 4043 JNIEXPORT void JNICALL JVM_RawMonitorDestroy(void *mon) {
duke@435 4044 VM_Exit::block_if_vm_exited();
duke@435 4045 JVMWrapper("JVM_RawMonitorDestroy");
duke@435 4046 delete ((Mutex*) mon);
duke@435 4047 }
duke@435 4048
duke@435 4049
duke@435 4050 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
duke@435 4051 VM_Exit::block_if_vm_exited();
duke@435 4052 JVMWrapper("JVM_RawMonitorEnter");
duke@435 4053 ((Mutex*) mon)->jvm_raw_lock();
duke@435 4054 return 0;
duke@435 4055 }
duke@435 4056
duke@435 4057
duke@435 4058 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
duke@435 4059 VM_Exit::block_if_vm_exited();
duke@435 4060 JVMWrapper("JVM_RawMonitorExit");
duke@435 4061 ((Mutex*) mon)->jvm_raw_unlock();
duke@435 4062 }
duke@435 4063
duke@435 4064
duke@435 4065 // Support for Serialization
duke@435 4066
duke@435 4067 typedef jfloat (JNICALL *IntBitsToFloatFn )(JNIEnv* env, jclass cb, jint value);
duke@435 4068 typedef jdouble (JNICALL *LongBitsToDoubleFn)(JNIEnv* env, jclass cb, jlong value);
duke@435 4069 typedef jint (JNICALL *FloatToIntBitsFn )(JNIEnv* env, jclass cb, jfloat value);
duke@435 4070 typedef jlong (JNICALL *DoubleToLongBitsFn)(JNIEnv* env, jclass cb, jdouble value);
duke@435 4071
duke@435 4072 static IntBitsToFloatFn int_bits_to_float_fn = NULL;
duke@435 4073 static LongBitsToDoubleFn long_bits_to_double_fn = NULL;
duke@435 4074 static FloatToIntBitsFn float_to_int_bits_fn = NULL;
duke@435 4075 static DoubleToLongBitsFn double_to_long_bits_fn = NULL;
duke@435 4076
duke@435 4077
duke@435 4078 void initialize_converter_functions() {
duke@435 4079 if (JDK_Version::is_gte_jdk14x_version()) {
duke@435 4080 // These functions only exist for compatibility with 1.3.1 and earlier
duke@435 4081 return;
duke@435 4082 }
duke@435 4083
duke@435 4084 // called from universe_post_init()
duke@435 4085 assert(
duke@435 4086 int_bits_to_float_fn == NULL &&
duke@435 4087 long_bits_to_double_fn == NULL &&
duke@435 4088 float_to_int_bits_fn == NULL &&
duke@435 4089 double_to_long_bits_fn == NULL ,
duke@435 4090 "initialization done twice"
duke@435 4091 );
duke@435 4092 // initialize
duke@435 4093 int_bits_to_float_fn = CAST_TO_FN_PTR(IntBitsToFloatFn , NativeLookup::base_library_lookup("java/lang/Float" , "intBitsToFloat" , "(I)F"));
duke@435 4094 long_bits_to_double_fn = CAST_TO_FN_PTR(LongBitsToDoubleFn, NativeLookup::base_library_lookup("java/lang/Double", "longBitsToDouble", "(J)D"));
duke@435 4095 float_to_int_bits_fn = CAST_TO_FN_PTR(FloatToIntBitsFn , NativeLookup::base_library_lookup("java/lang/Float" , "floatToIntBits" , "(F)I"));
duke@435 4096 double_to_long_bits_fn = CAST_TO_FN_PTR(DoubleToLongBitsFn, NativeLookup::base_library_lookup("java/lang/Double", "doubleToLongBits", "(D)J"));
duke@435 4097 // verify
duke@435 4098 assert(
duke@435 4099 int_bits_to_float_fn != NULL &&
duke@435 4100 long_bits_to_double_fn != NULL &&
duke@435 4101 float_to_int_bits_fn != NULL &&
duke@435 4102 double_to_long_bits_fn != NULL ,
duke@435 4103 "initialization failed"
duke@435 4104 );
duke@435 4105 }
duke@435 4106
duke@435 4107
duke@435 4108
duke@435 4109 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
duke@435 4110
coleenp@6823 4111 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
coleenp@6823 4112 Handle loader, Handle protection_domain,
coleenp@6823 4113 jboolean throwError, TRAPS) {
duke@435 4114 // Security Note:
duke@435 4115 // The Java level wrapper will perform the necessary security check allowing
coleenp@6823 4116 // us to pass the NULL as the initiating class loader. The VM is responsible for
coleenp@6823 4117 // the checkPackageAccess relative to the initiating class loader via the
coleenp@6823 4118 // protection_domain. The protection_domain is passed as NULL by the java code
coleenp@6823 4119 // if there is no security manager in 3-arg Class.forName().
coleenp@4037 4120 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
mchung@1313 4121
duke@435 4122 KlassHandle klass_handle(THREAD, klass);
duke@435 4123 // Check if we should initialize the class
duke@435 4124 if (init && klass_handle->oop_is_instance()) {
duke@435 4125 klass_handle->initialize(CHECK_NULL);
duke@435 4126 }
duke@435 4127 return (jclass) JNIHandles::make_local(env, klass_handle->java_mirror());
duke@435 4128 }
duke@435 4129
duke@435 4130
duke@435 4131 // Internal SQE debugging support ///////////////////////////////////////////////////////////
duke@435 4132
duke@435 4133 #ifndef PRODUCT
duke@435 4134
duke@435 4135 extern "C" {
duke@435 4136 JNIEXPORT jboolean JNICALL JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get);
duke@435 4137 JNIEXPORT jboolean JNICALL JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get);
duke@435 4138 JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj);
duke@435 4139 }
duke@435 4140
duke@435 4141 JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get))
duke@435 4142 JVMWrapper("JVM_AccessBoolVMFlag");
twisti@5790 4143 return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, Flag::INTERNAL);
duke@435 4144 JVM_END
duke@435 4145
duke@435 4146 JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get))
duke@435 4147 JVMWrapper("JVM_AccessVMIntFlag");
duke@435 4148 intx v;
twisti@5790 4149 jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, Flag::INTERNAL);
duke@435 4150 *value = (jint)v;
duke@435 4151 return result;
duke@435 4152 JVM_END
duke@435 4153
duke@435 4154
duke@435 4155 JVM_ENTRY(void, JVM_VMBreakPoint(JNIEnv *env, jobject obj))
duke@435 4156 JVMWrapper("JVM_VMBreakPoint");
duke@435 4157 oop the_obj = JNIHandles::resolve(obj);
duke@435 4158 BREAKPOINT;
duke@435 4159 JVM_END
duke@435 4160
duke@435 4161
duke@435 4162 #endif
duke@435 4163
duke@435 4164
duke@435 4165 // Method ///////////////////////////////////////////////////////////////////////////////////////////
duke@435 4166
duke@435 4167 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
duke@435 4168 JVMWrapper("JVM_InvokeMethod");
duke@435 4169 Handle method_handle;
duke@435 4170 if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
duke@435 4171 method_handle = Handle(THREAD, JNIHandles::resolve(method));
duke@435 4172 Handle receiver(THREAD, JNIHandles::resolve(obj));
duke@435 4173 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
duke@435 4174 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
duke@435 4175 jobject res = JNIHandles::make_local(env, result);
duke@435 4176 if (JvmtiExport::should_post_vm_object_alloc()) {
duke@435 4177 oop ret_type = java_lang_reflect_Method::return_type(method_handle());
duke@435 4178 assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
duke@435 4179 if (java_lang_Class::is_primitive(ret_type)) {
duke@435 4180 // Only for primitive type vm allocates memory for java object.
duke@435 4181 // See box() method.
duke@435 4182 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
duke@435 4183 }
duke@435 4184 }
duke@435 4185 return res;
duke@435 4186 } else {
duke@435 4187 THROW_0(vmSymbols::java_lang_StackOverflowError());
duke@435 4188 }
duke@435 4189 JVM_END
duke@435 4190
duke@435 4191
duke@435 4192 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
duke@435 4193 JVMWrapper("JVM_NewInstanceFromConstructor");
duke@435 4194 oop constructor_mirror = JNIHandles::resolve(c);
duke@435 4195 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
duke@435 4196 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
duke@435 4197 jobject res = JNIHandles::make_local(env, result);
duke@435 4198 if (JvmtiExport::should_post_vm_object_alloc()) {
duke@435 4199 JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
duke@435 4200 }
duke@435 4201 return res;
duke@435 4202 JVM_END
duke@435 4203
duke@435 4204 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
duke@435 4205
duke@435 4206 JVM_LEAF(jboolean, JVM_SupportsCX8())
duke@435 4207 JVMWrapper("JVM_SupportsCX8");
duke@435 4208 return VM_Version::supports_cx8();
duke@435 4209 JVM_END
duke@435 4210
duke@435 4211
duke@435 4212 JVM_ENTRY(jboolean, JVM_CX8Field(JNIEnv *env, jobject obj, jfieldID fid, jlong oldVal, jlong newVal))
duke@435 4213 JVMWrapper("JVM_CX8Field");
duke@435 4214 jlong res;
duke@435 4215 oop o = JNIHandles::resolve(obj);
duke@435 4216 intptr_t fldOffs = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
duke@435 4217 volatile jlong* addr = (volatile jlong*)((address)o + fldOffs);
duke@435 4218
duke@435 4219 assert(VM_Version::supports_cx8(), "cx8 not supported");
duke@435 4220 res = Atomic::cmpxchg(newVal, addr, oldVal);
duke@435 4221
duke@435 4222 return res == oldVal;
duke@435 4223 JVM_END
duke@435 4224
kamg@551 4225 // DTrace ///////////////////////////////////////////////////////////////////
kamg@551 4226
kamg@551 4227 JVM_ENTRY(jint, JVM_DTraceGetVersion(JNIEnv* env))
kamg@551 4228 JVMWrapper("JVM_DTraceGetVersion");
kamg@551 4229 return (jint)JVM_TRACING_DTRACE_VERSION;
kamg@551 4230 JVM_END
kamg@551 4231
kamg@551 4232 JVM_ENTRY(jlong,JVM_DTraceActivate(
kamg@551 4233 JNIEnv* env, jint version, jstring module_name, jint providers_count,
kamg@551 4234 JVM_DTraceProvider* providers))
kamg@551 4235 JVMWrapper("JVM_DTraceActivate");
kamg@551 4236 return DTraceJSDT::activate(
kamg@551 4237 version, module_name, providers_count, providers, CHECK_0);
kamg@551 4238 JVM_END
kamg@551 4239
kamg@551 4240 JVM_ENTRY(jboolean,JVM_DTraceIsProbeEnabled(JNIEnv* env, jmethodID method))
kamg@551 4241 JVMWrapper("JVM_DTraceIsProbeEnabled");
kamg@551 4242 return DTraceJSDT::is_probe_enabled(method);
kamg@551 4243 JVM_END
kamg@551 4244
kamg@551 4245 JVM_ENTRY(void,JVM_DTraceDispose(JNIEnv* env, jlong handle))
kamg@551 4246 JVMWrapper("JVM_DTraceDispose");
kamg@551 4247 DTraceJSDT::dispose(handle);
kamg@551 4248 JVM_END
kamg@551 4249
kamg@551 4250 JVM_ENTRY(jboolean,JVM_DTraceIsSupported(JNIEnv* env))
kamg@551 4251 JVMWrapper("JVM_DTraceIsSupported");
kamg@551 4252 return DTraceJSDT::is_supported();
kamg@551 4253 JVM_END
kamg@551 4254
duke@435 4255 // Returns an array of all live Thread objects (VM internal JavaThreads,
duke@435 4256 // jvmti agent threads, and JNI attaching threads are skipped)
duke@435 4257 // See CR 6404306 regarding JNI attaching threads
duke@435 4258 JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy))
duke@435 4259 ResourceMark rm(THREAD);
duke@435 4260 ThreadsListEnumerator tle(THREAD, false, false);
duke@435 4261 JvmtiVMObjectAllocEventCollector oam;
duke@435 4262
duke@435 4263 int num_threads = tle.num_threads();
never@1577 4264 objArrayOop r = oopFactory::new_objArray(SystemDictionary::Thread_klass(), num_threads, CHECK_NULL);
duke@435 4265 objArrayHandle threads_ah(THREAD, r);
duke@435 4266
duke@435 4267 for (int i = 0; i < num_threads; i++) {
duke@435 4268 Handle h = tle.get_threadObj(i);
duke@435 4269 threads_ah->obj_at_put(i, h());
duke@435 4270 }
duke@435 4271
duke@435 4272 return (jobjectArray) JNIHandles::make_local(env, threads_ah());
duke@435 4273 JVM_END
duke@435 4274
duke@435 4275
duke@435 4276 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
duke@435 4277 // Return StackTraceElement[][], each element is the stack trace of a thread in
duke@435 4278 // the corresponding entry in the given threads array
duke@435 4279 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
duke@435 4280 JVMWrapper("JVM_DumpThreads");
duke@435 4281 JvmtiVMObjectAllocEventCollector oam;
duke@435 4282
duke@435 4283 // Check if threads is null
duke@435 4284 if (threads == NULL) {
duke@435 4285 THROW_(vmSymbols::java_lang_NullPointerException(), 0);
duke@435 4286 }
duke@435 4287
duke@435 4288 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
duke@435 4289 objArrayHandle ah(THREAD, a);
duke@435 4290 int num_threads = ah->length();
duke@435 4291 // check if threads is non-empty array
duke@435 4292 if (num_threads == 0) {
duke@435 4293 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
duke@435 4294 }
duke@435 4295
duke@435 4296 // check if threads is not an array of objects of Thread class
coleenp@4142 4297 Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
never@1577 4298 if (k != SystemDictionary::Thread_klass()) {
duke@435 4299 THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
duke@435 4300 }
duke@435 4301
duke@435 4302 ResourceMark rm(THREAD);
duke@435 4303
duke@435 4304 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
duke@435 4305 for (int i = 0; i < num_threads; i++) {
duke@435 4306 oop thread_obj = ah->obj_at(i);
duke@435 4307 instanceHandle h(THREAD, (instanceOop) thread_obj);
duke@435 4308 thread_handle_array->append(h);
duke@435 4309 }
duke@435 4310
duke@435 4311 Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
duke@435 4312 return (jobjectArray)JNIHandles::make_local(env, stacktraces());
duke@435 4313
duke@435 4314 JVM_END
duke@435 4315
duke@435 4316 // JVM monitoring and management support
duke@435 4317 JVM_ENTRY_NO_ENV(void*, JVM_GetManagement(jint version))
duke@435 4318 return Management::get_jmm_interface(version);
duke@435 4319 JVM_END
duke@435 4320
duke@435 4321 // com.sun.tools.attach.VirtualMachine agent properties support
duke@435 4322 //
duke@435 4323 // Initialize the agent properties with the properties maintained in the VM
duke@435 4324 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
duke@435 4325 JVMWrapper("JVM_InitAgentProperties");
duke@435 4326 ResourceMark rm;
duke@435 4327
duke@435 4328 Handle props(THREAD, JNIHandles::resolve_non_null(properties));
duke@435 4329
duke@435 4330 PUTPROP(props, "sun.java.command", Arguments::java_command());
duke@435 4331 PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags());
duke@435 4332 PUTPROP(props, "sun.jvm.args", Arguments::jvm_args());
duke@435 4333 return properties;
duke@435 4334 JVM_END
duke@435 4335
duke@435 4336 JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass))
duke@435 4337 {
duke@435 4338 JVMWrapper("JVM_GetEnclosingMethodInfo");
duke@435 4339 JvmtiVMObjectAllocEventCollector oam;
duke@435 4340
duke@435 4341 if (ofClass == NULL) {
duke@435 4342 return NULL;
duke@435 4343 }
duke@435 4344 Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass));
duke@435 4345 // Special handling for primitive objects
duke@435 4346 if (java_lang_Class::is_primitive(mirror())) {
duke@435 4347 return NULL;
duke@435 4348 }
coleenp@4037 4349 Klass* k = java_lang_Class::as_Klass(mirror());
hseigel@4278 4350 if (!k->oop_is_instance()) {
duke@435 4351 return NULL;
duke@435 4352 }
duke@435 4353 instanceKlassHandle ik_h(THREAD, k);
duke@435 4354 int encl_method_class_idx = ik_h->enclosing_method_class_index();
duke@435 4355 if (encl_method_class_idx == 0) {
duke@435 4356 return NULL;
duke@435 4357 }
never@1577 4358 objArrayOop dest_o = oopFactory::new_objArray(SystemDictionary::Object_klass(), 3, CHECK_NULL);
duke@435 4359 objArrayHandle dest(THREAD, dest_o);
coleenp@4037 4360 Klass* enc_k = ik_h->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
hseigel@4278 4361 dest->obj_at_put(0, enc_k->java_mirror());
duke@435 4362 int encl_method_method_idx = ik_h->enclosing_method_method_index();
duke@435 4363 if (encl_method_method_idx != 0) {
coleenp@2497 4364 Symbol* sym = ik_h->constants()->symbol_at(
duke@435 4365 extract_low_short_from_int(
duke@435 4366 ik_h->constants()->name_and_type_at(encl_method_method_idx)));
duke@435 4367 Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
duke@435 4368 dest->obj_at_put(1, str());
coleenp@2497 4369 sym = ik_h->constants()->symbol_at(
duke@435 4370 extract_high_short_from_int(
duke@435 4371 ik_h->constants()->name_and_type_at(encl_method_method_idx)));
duke@435 4372 str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
duke@435 4373 dest->obj_at_put(2, str());
duke@435 4374 }
duke@435 4375 return (jobjectArray) JNIHandles::make_local(dest());
duke@435 4376 }
duke@435 4377 JVM_END
duke@435 4378
duke@435 4379 JVM_ENTRY(jintArray, JVM_GetThreadStateValues(JNIEnv* env,
duke@435 4380 jint javaThreadState))
duke@435 4381 {
duke@435 4382 // If new thread states are added in future JDK and VM versions,
duke@435 4383 // this should check if the JDK version is compatible with thread
duke@435 4384 // states supported by the VM. Return NULL if not compatible.
duke@435 4385 //
duke@435 4386 // This function must map the VM java_lang_Thread::ThreadStatus
duke@435 4387 // to the Java thread state that the JDK supports.
duke@435 4388 //
duke@435 4389
duke@435 4390 typeArrayHandle values_h;
duke@435 4391 switch (javaThreadState) {
duke@435 4392 case JAVA_THREAD_STATE_NEW : {
duke@435 4393 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
duke@435 4394 values_h = typeArrayHandle(THREAD, r);
duke@435 4395 values_h->int_at_put(0, java_lang_Thread::NEW);
duke@435 4396 break;
duke@435 4397 }
duke@435 4398 case JAVA_THREAD_STATE_RUNNABLE : {
duke@435 4399 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
duke@435 4400 values_h = typeArrayHandle(THREAD, r);
duke@435 4401 values_h->int_at_put(0, java_lang_Thread::RUNNABLE);
duke@435 4402 break;
duke@435 4403 }
duke@435 4404 case JAVA_THREAD_STATE_BLOCKED : {
duke@435 4405 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
duke@435 4406 values_h = typeArrayHandle(THREAD, r);
duke@435 4407 values_h->int_at_put(0, java_lang_Thread::BLOCKED_ON_MONITOR_ENTER);
duke@435 4408 break;
duke@435 4409 }
duke@435 4410 case JAVA_THREAD_STATE_WAITING : {
duke@435 4411 typeArrayOop r = oopFactory::new_typeArray(T_INT, 2, CHECK_NULL);
duke@435 4412 values_h = typeArrayHandle(THREAD, r);
duke@435 4413 values_h->int_at_put(0, java_lang_Thread::IN_OBJECT_WAIT);
duke@435 4414 values_h->int_at_put(1, java_lang_Thread::PARKED);
duke@435 4415 break;
duke@435 4416 }
duke@435 4417 case JAVA_THREAD_STATE_TIMED_WAITING : {
duke@435 4418 typeArrayOop r = oopFactory::new_typeArray(T_INT, 3, CHECK_NULL);
duke@435 4419 values_h = typeArrayHandle(THREAD, r);
duke@435 4420 values_h->int_at_put(0, java_lang_Thread::SLEEPING);
duke@435 4421 values_h->int_at_put(1, java_lang_Thread::IN_OBJECT_WAIT_TIMED);
duke@435 4422 values_h->int_at_put(2, java_lang_Thread::PARKED_TIMED);
duke@435 4423 break;
duke@435 4424 }
duke@435 4425 case JAVA_THREAD_STATE_TERMINATED : {
duke@435 4426 typeArrayOop r = oopFactory::new_typeArray(T_INT, 1, CHECK_NULL);
duke@435 4427 values_h = typeArrayHandle(THREAD, r);
duke@435 4428 values_h->int_at_put(0, java_lang_Thread::TERMINATED);
duke@435 4429 break;
duke@435 4430 }
duke@435 4431 default:
duke@435 4432 // Unknown state - probably incompatible JDK version
duke@435 4433 return NULL;
duke@435 4434 }
duke@435 4435
duke@435 4436 return (jintArray) JNIHandles::make_local(env, values_h());
duke@435 4437 }
duke@435 4438 JVM_END
duke@435 4439
duke@435 4440
duke@435 4441 JVM_ENTRY(jobjectArray, JVM_GetThreadStateNames(JNIEnv* env,
duke@435 4442 jint javaThreadState,
duke@435 4443 jintArray values))
duke@435 4444 {
duke@435 4445 // If new thread states are added in future JDK and VM versions,
duke@435 4446 // this should check if the JDK version is compatible with thread
duke@435 4447 // states supported by the VM. Return NULL if not compatible.
duke@435 4448 //
duke@435 4449 // This function must map the VM java_lang_Thread::ThreadStatus
duke@435 4450 // to the Java thread state that the JDK supports.
duke@435 4451 //
duke@435 4452
duke@435 4453 ResourceMark rm;
duke@435 4454
duke@435 4455 // Check if threads is null
duke@435 4456 if (values == NULL) {
duke@435 4457 THROW_(vmSymbols::java_lang_NullPointerException(), 0);
duke@435 4458 }
duke@435 4459
duke@435 4460 typeArrayOop v = typeArrayOop(JNIHandles::resolve_non_null(values));
duke@435 4461 typeArrayHandle values_h(THREAD, v);
duke@435 4462
duke@435 4463 objArrayHandle names_h;
duke@435 4464 switch (javaThreadState) {
duke@435 4465 case JAVA_THREAD_STATE_NEW : {
duke@435 4466 assert(values_h->length() == 1 &&
duke@435 4467 values_h->int_at(0) == java_lang_Thread::NEW,
duke@435 4468 "Invalid threadStatus value");
duke@435 4469
never@1577 4470 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4471 1, /* only 1 substate */
duke@435 4472 CHECK_NULL);
duke@435 4473 names_h = objArrayHandle(THREAD, r);
duke@435 4474 Handle name = java_lang_String::create_from_str("NEW", CHECK_NULL);
duke@435 4475 names_h->obj_at_put(0, name());
duke@435 4476 break;
duke@435 4477 }
duke@435 4478 case JAVA_THREAD_STATE_RUNNABLE : {
duke@435 4479 assert(values_h->length() == 1 &&
duke@435 4480 values_h->int_at(0) == java_lang_Thread::RUNNABLE,
duke@435 4481 "Invalid threadStatus value");
duke@435 4482
never@1577 4483 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4484 1, /* only 1 substate */
duke@435 4485 CHECK_NULL);
duke@435 4486 names_h = objArrayHandle(THREAD, r);
duke@435 4487 Handle name = java_lang_String::create_from_str("RUNNABLE", CHECK_NULL);
duke@435 4488 names_h->obj_at_put(0, name());
duke@435 4489 break;
duke@435 4490 }
duke@435 4491 case JAVA_THREAD_STATE_BLOCKED : {
duke@435 4492 assert(values_h->length() == 1 &&
duke@435 4493 values_h->int_at(0) == java_lang_Thread::BLOCKED_ON_MONITOR_ENTER,
duke@435 4494 "Invalid threadStatus value");
duke@435 4495
never@1577 4496 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4497 1, /* only 1 substate */
duke@435 4498 CHECK_NULL);
duke@435 4499 names_h = objArrayHandle(THREAD, r);
duke@435 4500 Handle name = java_lang_String::create_from_str("BLOCKED", CHECK_NULL);
duke@435 4501 names_h->obj_at_put(0, name());
duke@435 4502 break;
duke@435 4503 }
duke@435 4504 case JAVA_THREAD_STATE_WAITING : {
duke@435 4505 assert(values_h->length() == 2 &&
duke@435 4506 values_h->int_at(0) == java_lang_Thread::IN_OBJECT_WAIT &&
duke@435 4507 values_h->int_at(1) == java_lang_Thread::PARKED,
duke@435 4508 "Invalid threadStatus value");
never@1577 4509 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4510 2, /* number of substates */
duke@435 4511 CHECK_NULL);
duke@435 4512 names_h = objArrayHandle(THREAD, r);
duke@435 4513 Handle name0 = java_lang_String::create_from_str("WAITING.OBJECT_WAIT",
duke@435 4514 CHECK_NULL);
duke@435 4515 Handle name1 = java_lang_String::create_from_str("WAITING.PARKED",
duke@435 4516 CHECK_NULL);
duke@435 4517 names_h->obj_at_put(0, name0());
duke@435 4518 names_h->obj_at_put(1, name1());
duke@435 4519 break;
duke@435 4520 }
duke@435 4521 case JAVA_THREAD_STATE_TIMED_WAITING : {
duke@435 4522 assert(values_h->length() == 3 &&
duke@435 4523 values_h->int_at(0) == java_lang_Thread::SLEEPING &&
duke@435 4524 values_h->int_at(1) == java_lang_Thread::IN_OBJECT_WAIT_TIMED &&
duke@435 4525 values_h->int_at(2) == java_lang_Thread::PARKED_TIMED,
duke@435 4526 "Invalid threadStatus value");
never@1577 4527 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4528 3, /* number of substates */
duke@435 4529 CHECK_NULL);
duke@435 4530 names_h = objArrayHandle(THREAD, r);
duke@435 4531 Handle name0 = java_lang_String::create_from_str("TIMED_WAITING.SLEEPING",
duke@435 4532 CHECK_NULL);
duke@435 4533 Handle name1 = java_lang_String::create_from_str("TIMED_WAITING.OBJECT_WAIT",
duke@435 4534 CHECK_NULL);
duke@435 4535 Handle name2 = java_lang_String::create_from_str("TIMED_WAITING.PARKED",
duke@435 4536 CHECK_NULL);
duke@435 4537 names_h->obj_at_put(0, name0());
duke@435 4538 names_h->obj_at_put(1, name1());
duke@435 4539 names_h->obj_at_put(2, name2());
duke@435 4540 break;
duke@435 4541 }
duke@435 4542 case JAVA_THREAD_STATE_TERMINATED : {
duke@435 4543 assert(values_h->length() == 1 &&
duke@435 4544 values_h->int_at(0) == java_lang_Thread::TERMINATED,
duke@435 4545 "Invalid threadStatus value");
never@1577 4546 objArrayOop r = oopFactory::new_objArray(SystemDictionary::String_klass(),
duke@435 4547 1, /* only 1 substate */
duke@435 4548 CHECK_NULL);
duke@435 4549 names_h = objArrayHandle(THREAD, r);
duke@435 4550 Handle name = java_lang_String::create_from_str("TERMINATED", CHECK_NULL);
duke@435 4551 names_h->obj_at_put(0, name());
duke@435 4552 break;
duke@435 4553 }
duke@435 4554 default:
duke@435 4555 // Unknown state - probably incompatible JDK version
duke@435 4556 return NULL;
duke@435 4557 }
duke@435 4558 return (jobjectArray) JNIHandles::make_local(env, names_h());
duke@435 4559 }
duke@435 4560 JVM_END
duke@435 4561
duke@435 4562 JVM_ENTRY(void, JVM_GetVersionInfo(JNIEnv* env, jvm_version_info* info, size_t info_size))
duke@435 4563 {
igerasim@7404 4564 memset(info, 0, info_size);
duke@435 4565
duke@435 4566 info->jvm_version = Abstract_VM_Version::jvm_version();
duke@435 4567 info->update_version = 0; /* 0 in HotSpot Express VM */
duke@435 4568 info->special_update_version = 0; /* 0 in HotSpot Express VM */
duke@435 4569
duke@435 4570 // when we add a new capability in the jvm_version_info struct, we should also
duke@435 4571 // consider to expose this new capability in the sun.rt.jvmCapabilities jvmstat
duke@435 4572 // counter defined in runtimeService.cpp.
duke@435 4573 info->is_attachable = AttachListener::is_attach_supported();
duke@435 4574 }
duke@435 4575 JVM_END

mercurial