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