src/share/vm/prims/jvm.cpp

Fri, 10 May 2013 08:27:30 -0700

author
minqi
date
Fri, 10 May 2013 08:27:30 -0700
changeset 5097
92ef81e2f571
parent 4870
cd9ad42dfde0
child 5176
6bd680e9ea35
child 5249
ce9ecec70f99
permissions
-rw-r--r--

8003557: NPG: Klass* const k should be const Klass* k.
Summary: With NPG, const KlassOop klass which is in fact a definition converted to Klass* const, which is not the original intention. The right usage is converting them to const Klass*.
Reviewed-by: coleenp, kvn
Contributed-by: yumin.qi@oracle.com

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

mercurial