annotate src/share/vm/prims/jvm.cpp @ 2729:19241ae0d839

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