Fri, 13 Sep 2013 12:48:50 -0700
8024346: ~CautiouslyPreserveExceptionMark - assert(!_thread->has_pending_exception()) failed: unexpected exception generated
Summary: Pending exceptions must be handled properly after a call to the JVMTI merge_cp_and_rewrite
Reviewed-by: coleenp, dholmes
Contributed-by: serguei.spitsyn@oracle.com
duke@435 | 1 | /* |
bpittore@4793 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
coleenp@4148 | 3 | * Copyright (c) 2012 Red Hat, Inc. |
duke@435 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 5 | * |
duke@435 | 6 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 7 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 8 | * published by the Free Software Foundation. |
duke@435 | 9 | * |
duke@435 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 14 | * accompanied this code). |
duke@435 | 15 | * |
duke@435 | 16 | * You should have received a copy of the GNU General Public License version |
duke@435 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 19 | * |
trims@1907 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 21 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 22 | * questions. |
duke@435 | 23 | * |
duke@435 | 24 | */ |
duke@435 | 25 | |
stefank@2314 | 26 | #include "precompiled.hpp" |
minqi@4267 | 27 | #include "ci/ciReplay.hpp" |
coleenp@3865 | 28 | #include "classfile/altHashing.hpp" |
stefank@2314 | 29 | #include "classfile/classLoader.hpp" |
stefank@2314 | 30 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 31 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 32 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 33 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 34 | #include "interpreter/linkResolver.hpp" |
jprovino@4542 | 35 | #include "utilities/macros.hpp" |
jprovino@4542 | 36 | #if INCLUDE_ALL_GCS |
johnc@2781 | 37 | #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" |
jprovino@4542 | 38 | #endif // INCLUDE_ALL_GCS |
zgu@3900 | 39 | #include "memory/allocation.hpp" |
stefank@2314 | 40 | #include "memory/allocation.inline.hpp" |
stefank@2314 | 41 | #include "memory/gcLocker.inline.hpp" |
stefank@2314 | 42 | #include "memory/oopFactory.hpp" |
stefank@2314 | 43 | #include "memory/universe.inline.hpp" |
stefank@2314 | 44 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 45 | #include "oops/instanceOop.hpp" |
stefank@2314 | 46 | #include "oops/markOop.hpp" |
coleenp@4037 | 47 | #include "oops/method.hpp" |
stefank@2314 | 48 | #include "oops/objArrayKlass.hpp" |
stefank@2314 | 49 | #include "oops/objArrayOop.hpp" |
stefank@2314 | 50 | #include "oops/oop.inline.hpp" |
coleenp@2497 | 51 | #include "oops/symbol.hpp" |
stefank@2314 | 52 | #include "oops/typeArrayKlass.hpp" |
stefank@2314 | 53 | #include "oops/typeArrayOop.hpp" |
stefank@2314 | 54 | #include "prims/jni.h" |
stefank@2314 | 55 | #include "prims/jniCheck.hpp" |
phh@3427 | 56 | #include "prims/jniExport.hpp" |
stefank@2314 | 57 | #include "prims/jniFastGetField.hpp" |
stefank@2314 | 58 | #include "prims/jvm.h" |
stefank@2314 | 59 | #include "prims/jvm_misc.hpp" |
stefank@2314 | 60 | #include "prims/jvmtiExport.hpp" |
stefank@2314 | 61 | #include "prims/jvmtiThreadState.hpp" |
stefank@2314 | 62 | #include "runtime/compilationPolicy.hpp" |
stefank@2314 | 63 | #include "runtime/fieldDescriptor.hpp" |
stefank@2314 | 64 | #include "runtime/fprofiler.hpp" |
stefank@2314 | 65 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 66 | #include "runtime/interfaceSupport.hpp" |
stefank@2314 | 67 | #include "runtime/java.hpp" |
stefank@2314 | 68 | #include "runtime/javaCalls.hpp" |
stefank@2314 | 69 | #include "runtime/jfieldIDWorkaround.hpp" |
stefank@2314 | 70 | #include "runtime/reflection.hpp" |
stefank@2314 | 71 | #include "runtime/sharedRuntime.hpp" |
stefank@2314 | 72 | #include "runtime/signature.hpp" |
stefank@4299 | 73 | #include "runtime/thread.inline.hpp" |
stefank@2314 | 74 | #include "runtime/vm_operations.hpp" |
stefank@2314 | 75 | #include "services/runtimeService.hpp" |
phh@3427 | 76 | #include "trace/tracing.hpp" |
stefank@2314 | 77 | #include "utilities/defaultStream.hpp" |
stefank@2314 | 78 | #include "utilities/dtrace.hpp" |
stefank@2314 | 79 | #include "utilities/events.hpp" |
stefank@2314 | 80 | #include "utilities/histogram.hpp" |
stefank@2314 | 81 | #ifdef TARGET_OS_FAMILY_linux |
stefank@2314 | 82 | # include "os_linux.inline.hpp" |
stefank@2314 | 83 | #endif |
stefank@2314 | 84 | #ifdef TARGET_OS_FAMILY_solaris |
stefank@2314 | 85 | # include "os_solaris.inline.hpp" |
stefank@2314 | 86 | #endif |
stefank@2314 | 87 | #ifdef TARGET_OS_FAMILY_windows |
stefank@2314 | 88 | # include "os_windows.inline.hpp" |
stefank@2314 | 89 | #endif |
never@3156 | 90 | #ifdef TARGET_OS_FAMILY_bsd |
never@3156 | 91 | # include "os_bsd.inline.hpp" |
never@3156 | 92 | #endif |
duke@435 | 93 | |
bpittore@4793 | 94 | static jint CurrentVersion = JNI_VERSION_1_8; |
duke@435 | 95 | |
duke@435 | 96 | |
duke@435 | 97 | // The DT_RETURN_MARK macros create a scoped object to fire the dtrace |
duke@435 | 98 | // '-return' probe regardless of the return path is taken out of the function. |
duke@435 | 99 | // Methods that have multiple return paths use this to avoid having to |
duke@435 | 100 | // instrument each return path. Methods that use CHECK or THROW must use this |
duke@435 | 101 | // since those macros can cause an immedate uninstrumented return. |
duke@435 | 102 | // |
duke@435 | 103 | // In order to get the return value, a reference to the variable containing |
duke@435 | 104 | // the return value must be passed to the contructor of the object, and |
duke@435 | 105 | // the return value must be set before return (since the mark object has |
duke@435 | 106 | // a reference to it). |
duke@435 | 107 | // |
duke@435 | 108 | // Example: |
duke@435 | 109 | // DT_RETURN_MARK_DECL(SomeFunc, int); |
duke@435 | 110 | // JNI_ENTRY(int, SomeFunc, ...) |
duke@435 | 111 | // int return_value = 0; |
duke@435 | 112 | // DT_RETURN_MARK(SomeFunc, int, (const int&)return_value); |
duke@435 | 113 | // foo(CHECK_0) |
duke@435 | 114 | // return_value = 5; |
duke@435 | 115 | // return return_value; |
duke@435 | 116 | // JNI_END |
dcubed@3202 | 117 | #ifndef USDT2 |
duke@435 | 118 | #define DT_RETURN_MARK_DECL(name, type) \ |
duke@435 | 119 | HS_DTRACE_PROBE_DECL1(hotspot_jni, name##__return, type); \ |
duke@435 | 120 | DTRACE_ONLY( \ |
duke@435 | 121 | class DTraceReturnProbeMark_##name { \ |
duke@435 | 122 | public: \ |
duke@435 | 123 | const type& _ret_ref; \ |
duke@435 | 124 | DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ |
duke@435 | 125 | ~DTraceReturnProbeMark_##name() { \ |
duke@435 | 126 | HS_DTRACE_PROBE1(hotspot_jni, name##__return, _ret_ref); \ |
duke@435 | 127 | } \ |
duke@435 | 128 | } \ |
duke@435 | 129 | ) |
duke@435 | 130 | // Void functions are simpler since there's no return value |
duke@435 | 131 | #define DT_VOID_RETURN_MARK_DECL(name) \ |
duke@435 | 132 | HS_DTRACE_PROBE_DECL0(hotspot_jni, name##__return); \ |
duke@435 | 133 | DTRACE_ONLY( \ |
duke@435 | 134 | class DTraceReturnProbeMark_##name { \ |
duke@435 | 135 | public: \ |
duke@435 | 136 | ~DTraceReturnProbeMark_##name() { \ |
duke@435 | 137 | HS_DTRACE_PROBE0(hotspot_jni, name##__return); \ |
duke@435 | 138 | } \ |
duke@435 | 139 | } \ |
duke@435 | 140 | ) |
duke@435 | 141 | |
dcubed@3202 | 142 | #else /* USDT2 */ |
dcubed@3202 | 143 | |
dcubed@3202 | 144 | #define DT_RETURN_MARK_DECL(name, type, probe) \ |
dcubed@3202 | 145 | DTRACE_ONLY( \ |
dcubed@3202 | 146 | class DTraceReturnProbeMark_##name { \ |
dcubed@3202 | 147 | public: \ |
dcubed@3202 | 148 | const type& _ret_ref; \ |
dcubed@3202 | 149 | DTraceReturnProbeMark_##name(const type& v) : _ret_ref(v) {} \ |
dcubed@3202 | 150 | ~DTraceReturnProbeMark_##name() { \ |
dcubed@3202 | 151 | probe; \ |
dcubed@3202 | 152 | } \ |
dcubed@3202 | 153 | } \ |
dcubed@3202 | 154 | ) |
dcubed@3202 | 155 | // Void functions are simpler since there's no return value |
dcubed@3202 | 156 | #define DT_VOID_RETURN_MARK_DECL(name, probe) \ |
dcubed@3202 | 157 | DTRACE_ONLY( \ |
dcubed@3202 | 158 | class DTraceReturnProbeMark_##name { \ |
dcubed@3202 | 159 | public: \ |
dcubed@3202 | 160 | ~DTraceReturnProbeMark_##name() { \ |
dcubed@3202 | 161 | probe; \ |
dcubed@3202 | 162 | } \ |
dcubed@3202 | 163 | } \ |
dcubed@3202 | 164 | ) |
dcubed@3202 | 165 | #endif /* USDT2 */ |
duke@435 | 166 | |
duke@435 | 167 | // Place these macros in the function to mark the return. Non-void |
duke@435 | 168 | // functions need the type and address of the return value. |
duke@435 | 169 | #define DT_RETURN_MARK(name, type, ref) \ |
duke@435 | 170 | DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark(ref) ) |
duke@435 | 171 | #define DT_VOID_RETURN_MARK(name) \ |
duke@435 | 172 | DTRACE_ONLY( DTraceReturnProbeMark_##name dtrace_return_mark ) |
duke@435 | 173 | |
duke@435 | 174 | |
duke@435 | 175 | // Use these to select distinct code for floating-point vs. non-floating point |
duke@435 | 176 | // situations. Used from within common macros where we need slightly |
duke@435 | 177 | // different behavior for Float/Double |
duke@435 | 178 | #define FP_SELECT_Boolean(intcode, fpcode) intcode |
duke@435 | 179 | #define FP_SELECT_Byte(intcode, fpcode) intcode |
duke@435 | 180 | #define FP_SELECT_Char(intcode, fpcode) intcode |
duke@435 | 181 | #define FP_SELECT_Short(intcode, fpcode) intcode |
duke@435 | 182 | #define FP_SELECT_Object(intcode, fpcode) intcode |
duke@435 | 183 | #define FP_SELECT_Int(intcode, fpcode) intcode |
duke@435 | 184 | #define FP_SELECT_Long(intcode, fpcode) intcode |
duke@435 | 185 | #define FP_SELECT_Float(intcode, fpcode) fpcode |
duke@435 | 186 | #define FP_SELECT_Double(intcode, fpcode) fpcode |
duke@435 | 187 | #define FP_SELECT(TypeName, intcode, fpcode) \ |
duke@435 | 188 | FP_SELECT_##TypeName(intcode, fpcode) |
duke@435 | 189 | |
duke@435 | 190 | #define COMMA , |
duke@435 | 191 | |
duke@435 | 192 | // Choose DT_RETURN_MARK macros based on the type: float/double -> void |
duke@435 | 193 | // (dtrace doesn't do FP yet) |
dcubed@3202 | 194 | #ifndef USDT2 |
duke@435 | 195 | #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type) \ |
duke@435 | 196 | FP_SELECT(TypeName, \ |
duke@435 | 197 | DT_RETURN_MARK_DECL(name, type), DT_VOID_RETURN_MARK_DECL(name) ) |
dcubed@3202 | 198 | #else /* USDT2 */ |
dcubed@3202 | 199 | #define DT_RETURN_MARK_DECL_FOR(TypeName, name, type, probe) \ |
dcubed@3202 | 200 | FP_SELECT(TypeName, \ |
dcubed@3202 | 201 | DT_RETURN_MARK_DECL(name, type, probe), DT_VOID_RETURN_MARK_DECL(name, probe) ) |
dcubed@3202 | 202 | #endif /* USDT2 */ |
duke@435 | 203 | #define DT_RETURN_MARK_FOR(TypeName, name, type, ref) \ |
duke@435 | 204 | FP_SELECT(TypeName, \ |
duke@435 | 205 | DT_RETURN_MARK(name, type, ref), DT_VOID_RETURN_MARK(name) ) |
duke@435 | 206 | |
duke@435 | 207 | |
duke@435 | 208 | // out-of-line helpers for class jfieldIDWorkaround: |
duke@435 | 209 | |
coleenp@4037 | 210 | bool jfieldIDWorkaround::is_valid_jfieldID(Klass* k, jfieldID id) { |
duke@435 | 211 | if (jfieldIDWorkaround::is_instance_jfieldID(k, id)) { |
duke@435 | 212 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 213 | intptr_t offset = raw_instance_offset(id); |
duke@435 | 214 | if (is_checked_jfieldID(id)) { |
duke@435 | 215 | if (!klass_hash_ok(k, id)) { |
duke@435 | 216 | return false; |
duke@435 | 217 | } |
duke@435 | 218 | } |
coleenp@4037 | 219 | return InstanceKlass::cast(k)->contains_field_offset(offset); |
duke@435 | 220 | } else { |
duke@435 | 221 | JNIid* result = (JNIid*) id; |
duke@435 | 222 | #ifdef ASSERT |
duke@435 | 223 | return result != NULL && result->is_static_field_id(); |
duke@435 | 224 | #else |
duke@435 | 225 | return result != NULL; |
duke@435 | 226 | #endif |
duke@435 | 227 | } |
duke@435 | 228 | } |
duke@435 | 229 | |
duke@435 | 230 | |
coleenp@4037 | 231 | intptr_t jfieldIDWorkaround::encode_klass_hash(Klass* k, intptr_t offset) { |
duke@435 | 232 | if (offset <= small_offset_mask) { |
coleenp@4037 | 233 | Klass* field_klass = k; |
hseigel@4278 | 234 | Klass* super_klass = field_klass->super(); |
coleenp@548 | 235 | // With compressed oops the most super class with nonstatic fields would |
coleenp@548 | 236 | // be the owner of fields embedded in the header. |
coleenp@4037 | 237 | while (InstanceKlass::cast(super_klass)->has_nonstatic_fields() && |
coleenp@4037 | 238 | InstanceKlass::cast(super_klass)->contains_field_offset(offset)) { |
duke@435 | 239 | field_klass = super_klass; // super contains the field also |
hseigel@4278 | 240 | super_klass = field_klass->super(); |
duke@435 | 241 | } |
duke@435 | 242 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 243 | uintptr_t klass_hash = field_klass->identity_hash(); |
duke@435 | 244 | return ((klass_hash & klass_mask) << klass_shift) | checked_mask_in_place; |
duke@435 | 245 | } else { |
duke@435 | 246 | #if 0 |
duke@435 | 247 | #ifndef PRODUCT |
duke@435 | 248 | { |
duke@435 | 249 | ResourceMark rm; |
hseigel@4278 | 250 | warning("VerifyJNIFields: long offset %d in %s", offset, k->external_name()); |
duke@435 | 251 | } |
duke@435 | 252 | #endif |
duke@435 | 253 | #endif |
duke@435 | 254 | return 0; |
duke@435 | 255 | } |
duke@435 | 256 | } |
duke@435 | 257 | |
coleenp@4037 | 258 | bool jfieldIDWorkaround::klass_hash_ok(Klass* k, jfieldID id) { |
duke@435 | 259 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 260 | intptr_t klass_hash = (as_uint >> klass_shift) & klass_mask; |
duke@435 | 261 | do { |
duke@435 | 262 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 263 | // Could use a non-blocking query for identity_hash here... |
duke@435 | 264 | if ((k->identity_hash() & klass_mask) == klass_hash) |
duke@435 | 265 | return true; |
hseigel@4278 | 266 | k = k->super(); |
duke@435 | 267 | } while (k != NULL); |
duke@435 | 268 | return false; |
duke@435 | 269 | } |
duke@435 | 270 | |
coleenp@4037 | 271 | void jfieldIDWorkaround::verify_instance_jfieldID(Klass* k, jfieldID id) { |
duke@435 | 272 | guarantee(jfieldIDWorkaround::is_instance_jfieldID(k, id), "must be an instance field" ); |
duke@435 | 273 | uintptr_t as_uint = (uintptr_t) id; |
duke@435 | 274 | intptr_t offset = raw_instance_offset(id); |
duke@435 | 275 | if (VerifyJNIFields) { |
duke@435 | 276 | if (is_checked_jfieldID(id)) { |
duke@435 | 277 | guarantee(klass_hash_ok(k, id), |
duke@435 | 278 | "Bug in native code: jfieldID class must match object"); |
duke@435 | 279 | } else { |
duke@435 | 280 | #if 0 |
duke@435 | 281 | #ifndef PRODUCT |
duke@435 | 282 | if (Verbose) { |
duke@435 | 283 | ResourceMark rm; |
hseigel@4278 | 284 | warning("VerifyJNIFields: unverified offset %d for %s", offset, k->external_name()); |
duke@435 | 285 | } |
duke@435 | 286 | #endif |
duke@435 | 287 | #endif |
duke@435 | 288 | } |
duke@435 | 289 | } |
coleenp@4037 | 290 | guarantee(InstanceKlass::cast(k)->contains_field_offset(offset), |
duke@435 | 291 | "Bug in native code: jfieldID offset must address interior of object"); |
duke@435 | 292 | } |
duke@435 | 293 | |
duke@435 | 294 | // Pick a reasonable higher bound for local capacity requested |
duke@435 | 295 | // for EnsureLocalCapacity and PushLocalFrame. We don't want it too |
duke@435 | 296 | // high because a test (or very unusual application) may try to allocate |
duke@435 | 297 | // that many handles and run out of swap space. An implementation is |
duke@435 | 298 | // permitted to allocate more handles than the ensured capacity, so this |
duke@435 | 299 | // value is set high enough to prevent compatibility problems. |
duke@435 | 300 | const int MAX_REASONABLE_LOCAL_CAPACITY = 4*K; |
duke@435 | 301 | |
duke@435 | 302 | |
duke@435 | 303 | // Wrapper to trace JNI functions |
duke@435 | 304 | |
duke@435 | 305 | #ifdef ASSERT |
duke@435 | 306 | Histogram* JNIHistogram; |
duke@435 | 307 | static volatile jint JNIHistogram_lock = 0; |
duke@435 | 308 | |
duke@435 | 309 | class JNITraceWrapper : public StackObj { |
duke@435 | 310 | public: |
duke@435 | 311 | JNITraceWrapper(const char* format, ...) { |
duke@435 | 312 | if (TraceJNICalls) { |
duke@435 | 313 | va_list ap; |
duke@435 | 314 | va_start(ap, format); |
duke@435 | 315 | tty->print("JNI "); |
duke@435 | 316 | tty->vprint_cr(format, ap); |
duke@435 | 317 | va_end(ap); |
duke@435 | 318 | } |
duke@435 | 319 | } |
duke@435 | 320 | }; |
duke@435 | 321 | |
duke@435 | 322 | class JNIHistogramElement : public HistogramElement { |
duke@435 | 323 | public: |
duke@435 | 324 | JNIHistogramElement(const char* name); |
duke@435 | 325 | }; |
duke@435 | 326 | |
duke@435 | 327 | JNIHistogramElement::JNIHistogramElement(const char* elementName) { |
duke@435 | 328 | _name = elementName; |
duke@435 | 329 | uintx count = 0; |
duke@435 | 330 | |
duke@435 | 331 | while (Atomic::cmpxchg(1, &JNIHistogram_lock, 0) != 0) { |
duke@435 | 332 | while (OrderAccess::load_acquire(&JNIHistogram_lock) != 0) { |
duke@435 | 333 | count +=1; |
duke@435 | 334 | if ( (WarnOnStalledSpinLock > 0) |
duke@435 | 335 | && (count % WarnOnStalledSpinLock == 0)) { |
duke@435 | 336 | warning("JNIHistogram_lock seems to be stalled"); |
duke@435 | 337 | } |
duke@435 | 338 | } |
duke@435 | 339 | } |
duke@435 | 340 | |
duke@435 | 341 | |
duke@435 | 342 | if(JNIHistogram == NULL) |
duke@435 | 343 | JNIHistogram = new Histogram("JNI Call Counts",100); |
duke@435 | 344 | |
duke@435 | 345 | JNIHistogram->add_element(this); |
duke@435 | 346 | Atomic::dec(&JNIHistogram_lock); |
duke@435 | 347 | } |
duke@435 | 348 | |
duke@435 | 349 | #define JNICountWrapper(arg) \ |
duke@435 | 350 | static JNIHistogramElement* e = new JNIHistogramElement(arg); \ |
duke@435 | 351 | /* There is a MT-race condition in VC++. So we need to make sure that that e has been initialized */ \ |
duke@435 | 352 | if (e != NULL) e->increment_count() |
duke@435 | 353 | #define JNIWrapper(arg) JNICountWrapper(arg); JNITraceWrapper(arg) |
duke@435 | 354 | #else |
duke@435 | 355 | #define JNIWrapper(arg) |
duke@435 | 356 | #endif |
duke@435 | 357 | |
duke@435 | 358 | |
duke@435 | 359 | // Implementation of JNI entries |
duke@435 | 360 | |
dcubed@3202 | 361 | #ifndef USDT2 |
duke@435 | 362 | DT_RETURN_MARK_DECL(DefineClass, jclass); |
dcubed@3202 | 363 | #else /* USDT2 */ |
dcubed@3202 | 364 | DT_RETURN_MARK_DECL(DefineClass, jclass |
dcubed@3202 | 365 | , HOTSPOT_JNI_DEFINECLASS_RETURN(_ret_ref)); |
dcubed@3202 | 366 | #endif /* USDT2 */ |
duke@435 | 367 | |
duke@435 | 368 | JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderRef, |
duke@435 | 369 | const jbyte *buf, jsize bufLen)) |
duke@435 | 370 | JNIWrapper("DefineClass"); |
duke@435 | 371 | |
dcubed@3202 | 372 | #ifndef USDT2 |
duke@435 | 373 | DTRACE_PROBE5(hotspot_jni, DefineClass__entry, |
duke@435 | 374 | env, name, loaderRef, buf, bufLen); |
dcubed@3202 | 375 | #else /* USDT2 */ |
dcubed@3202 | 376 | HOTSPOT_JNI_DEFINECLASS_ENTRY( |
dcubed@3202 | 377 | env, (char*) name, loaderRef, (char*) buf, bufLen); |
dcubed@3202 | 378 | #endif /* USDT2 */ |
duke@435 | 379 | jclass cls = NULL; |
duke@435 | 380 | DT_RETURN_MARK(DefineClass, jclass, (const jclass&)cls); |
duke@435 | 381 | |
fparain@3828 | 382 | TempNewSymbol class_name = NULL; |
duke@435 | 383 | // Since exceptions can be thrown, class initialization can take place |
duke@435 | 384 | // if name is NULL no check for class name in .class stream has to be made. |
duke@435 | 385 | if (name != NULL) { |
duke@435 | 386 | const int str_len = (int)strlen(name); |
coleenp@2497 | 387 | if (str_len > Symbol::max_length()) { |
duke@435 | 388 | // It's impossible to create this class; the name cannot fit |
duke@435 | 389 | // into the constant pool. |
duke@435 | 390 | THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
duke@435 | 391 | } |
fparain@3828 | 392 | class_name = SymbolTable::new_symbol(name, CHECK_NULL); |
duke@435 | 393 | } |
duke@435 | 394 | ResourceMark rm(THREAD); |
duke@435 | 395 | ClassFileStream st((u1*) buf, bufLen, NULL); |
duke@435 | 396 | Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); |
duke@435 | 397 | |
duke@435 | 398 | if (UsePerfData && !class_loader.is_null()) { |
duke@435 | 399 | // check whether the current caller thread holds the lock or not. |
duke@435 | 400 | // If not, increment the corresponding counter |
duke@435 | 401 | if (ObjectSynchronizer:: |
duke@435 | 402 | query_lock_ownership((JavaThread*)THREAD, class_loader) != |
duke@435 | 403 | ObjectSynchronizer::owner_self) { |
duke@435 | 404 | ClassLoader::sync_JNIDefineClassLockFreeCounter()->inc(); |
duke@435 | 405 | } |
duke@435 | 406 | } |
coleenp@4037 | 407 | Klass* k = SystemDictionary::resolve_from_stream(class_name, class_loader, |
acorn@1408 | 408 | Handle(), &st, true, |
acorn@1408 | 409 | CHECK_NULL); |
duke@435 | 410 | |
acorn@1092 | 411 | if (TraceClassResolution && k != NULL) { |
acorn@1092 | 412 | trace_class_resolution(k); |
acorn@1092 | 413 | } |
acorn@1092 | 414 | |
duke@435 | 415 | cls = (jclass)JNIHandles::make_local( |
hseigel@4278 | 416 | env, k->java_mirror()); |
duke@435 | 417 | return cls; |
duke@435 | 418 | JNI_END |
duke@435 | 419 | |
duke@435 | 420 | |
duke@435 | 421 | |
duke@435 | 422 | static bool first_time_FindClass = true; |
duke@435 | 423 | |
dcubed@3202 | 424 | #ifndef USDT2 |
duke@435 | 425 | DT_RETURN_MARK_DECL(FindClass, jclass); |
dcubed@3202 | 426 | #else /* USDT2 */ |
dcubed@3202 | 427 | DT_RETURN_MARK_DECL(FindClass, jclass |
dcubed@3202 | 428 | , HOTSPOT_JNI_FINDCLASS_RETURN(_ret_ref)); |
dcubed@3202 | 429 | #endif /* USDT2 */ |
duke@435 | 430 | |
duke@435 | 431 | JNI_ENTRY(jclass, jni_FindClass(JNIEnv *env, const char *name)) |
duke@435 | 432 | JNIWrapper("FindClass"); |
dcubed@3202 | 433 | #ifndef USDT2 |
duke@435 | 434 | DTRACE_PROBE2(hotspot_jni, FindClass__entry, env, name); |
dcubed@3202 | 435 | #else /* USDT2 */ |
dcubed@3202 | 436 | HOTSPOT_JNI_FINDCLASS_ENTRY( |
dcubed@3202 | 437 | env, (char *)name); |
dcubed@3202 | 438 | #endif /* USDT2 */ |
duke@435 | 439 | |
duke@435 | 440 | jclass result = NULL; |
duke@435 | 441 | DT_RETURN_MARK(FindClass, jclass, (const jclass&)result); |
duke@435 | 442 | |
duke@435 | 443 | // Remember if we are the first invocation of jni_FindClass |
duke@435 | 444 | bool first_time = first_time_FindClass; |
duke@435 | 445 | first_time_FindClass = false; |
duke@435 | 446 | |
duke@435 | 447 | // Sanity check the name: it cannot be null or larger than the maximum size |
duke@435 | 448 | // name we can fit in the constant pool. |
coleenp@2497 | 449 | if (name == NULL || (int)strlen(name) > Symbol::max_length()) { |
duke@435 | 450 | THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), name); |
duke@435 | 451 | } |
duke@435 | 452 | |
duke@435 | 453 | //%note jni_3 |
duke@435 | 454 | Handle loader; |
duke@435 | 455 | Handle protection_domain; |
duke@435 | 456 | // Find calling class |
duke@435 | 457 | instanceKlassHandle k (THREAD, thread->security_get_caller_class(0)); |
duke@435 | 458 | if (k.not_null()) { |
duke@435 | 459 | loader = Handle(THREAD, k->class_loader()); |
duke@435 | 460 | // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed |
duke@435 | 461 | // in the correct class context. |
duke@435 | 462 | if (loader.is_null() && |
duke@435 | 463 | k->name() == vmSymbols::java_lang_ClassLoader_NativeLibrary()) { |
duke@435 | 464 | JavaValue result(T_OBJECT); |
duke@435 | 465 | JavaCalls::call_static(&result, k, |
coleenp@2497 | 466 | vmSymbols::getFromClass_name(), |
coleenp@2497 | 467 | vmSymbols::void_class_signature(), |
duke@435 | 468 | thread); |
duke@435 | 469 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 470 | Handle ex(thread, thread->pending_exception()); |
duke@435 | 471 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 472 | THROW_HANDLE_0(ex); |
duke@435 | 473 | } |
duke@435 | 474 | oop mirror = (oop) result.get_jobject(); |
duke@435 | 475 | loader = Handle(THREAD, |
coleenp@4037 | 476 | InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->class_loader()); |
duke@435 | 477 | protection_domain = Handle(THREAD, |
coleenp@4037 | 478 | InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->protection_domain()); |
duke@435 | 479 | } |
duke@435 | 480 | } else { |
duke@435 | 481 | // We call ClassLoader.getSystemClassLoader to obtain the system class loader. |
duke@435 | 482 | loader = Handle(THREAD, SystemDictionary::java_system_loader()); |
duke@435 | 483 | } |
duke@435 | 484 | |
coleenp@2497 | 485 | TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
duke@435 | 486 | result = find_class_from_class_loader(env, sym, true, loader, |
duke@435 | 487 | protection_domain, true, thread); |
duke@435 | 488 | |
acorn@1092 | 489 | if (TraceClassResolution && result != NULL) { |
coleenp@4037 | 490 | trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); |
acorn@1092 | 491 | } |
acorn@1092 | 492 | |
duke@435 | 493 | // If we were the first invocation of jni_FindClass, we enable compilation again |
duke@435 | 494 | // rather than just allowing invocation counter to overflow and decay. |
duke@435 | 495 | // Controlled by flag DelayCompilationDuringStartup. |
duke@435 | 496 | if (first_time && !CompileTheWorld) |
duke@435 | 497 | CompilationPolicy::completed_vm_startup(); |
duke@435 | 498 | |
duke@435 | 499 | return result; |
duke@435 | 500 | JNI_END |
duke@435 | 501 | |
dcubed@3202 | 502 | #ifndef USDT2 |
duke@435 | 503 | DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID); |
dcubed@3202 | 504 | #else /* USDT2 */ |
dcubed@3202 | 505 | DT_RETURN_MARK_DECL(FromReflectedMethod, jmethodID |
dcubed@3202 | 506 | , HOTSPOT_JNI_FROMREFLECTEDMETHOD_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 507 | #endif /* USDT2 */ |
duke@435 | 508 | |
duke@435 | 509 | JNI_ENTRY(jmethodID, jni_FromReflectedMethod(JNIEnv *env, jobject method)) |
duke@435 | 510 | JNIWrapper("FromReflectedMethod"); |
dcubed@3202 | 511 | #ifndef USDT2 |
duke@435 | 512 | DTRACE_PROBE2(hotspot_jni, FromReflectedMethod__entry, env, method); |
dcubed@3202 | 513 | #else /* USDT2 */ |
dcubed@3202 | 514 | HOTSPOT_JNI_FROMREFLECTEDMETHOD_ENTRY( |
dcubed@3202 | 515 | env, method); |
dcubed@3202 | 516 | #endif /* USDT2 */ |
duke@435 | 517 | jmethodID ret = NULL; |
duke@435 | 518 | DT_RETURN_MARK(FromReflectedMethod, jmethodID, (const jmethodID&)ret); |
duke@435 | 519 | |
duke@435 | 520 | // method is a handle to a java.lang.reflect.Method object |
duke@435 | 521 | oop reflected = JNIHandles::resolve_non_null(method); |
duke@435 | 522 | oop mirror = NULL; |
duke@435 | 523 | int slot = 0; |
duke@435 | 524 | |
never@1577 | 525 | if (reflected->klass() == SystemDictionary::reflect_Constructor_klass()) { |
duke@435 | 526 | mirror = java_lang_reflect_Constructor::clazz(reflected); |
duke@435 | 527 | slot = java_lang_reflect_Constructor::slot(reflected); |
duke@435 | 528 | } else { |
never@1577 | 529 | assert(reflected->klass() == SystemDictionary::reflect_Method_klass(), "wrong type"); |
duke@435 | 530 | mirror = java_lang_reflect_Method::clazz(reflected); |
duke@435 | 531 | slot = java_lang_reflect_Method::slot(reflected); |
duke@435 | 532 | } |
coleenp@4037 | 533 | Klass* k = java_lang_Class::as_Klass(mirror); |
duke@435 | 534 | |
duke@435 | 535 | KlassHandle k1(THREAD, k); |
duke@435 | 536 | // Make sure class is initialized before handing id's out to methods |
hseigel@4278 | 537 | k1()->initialize(CHECK_NULL); |
coleenp@4037 | 538 | Method* m = InstanceKlass::cast(k1())->method_with_idnum(slot); |
duke@435 | 539 | ret = m==NULL? NULL : m->jmethod_id(); // return NULL if reflected method deleted |
duke@435 | 540 | return ret; |
duke@435 | 541 | JNI_END |
duke@435 | 542 | |
dcubed@3202 | 543 | #ifndef USDT2 |
duke@435 | 544 | DT_RETURN_MARK_DECL(FromReflectedField, jfieldID); |
dcubed@3202 | 545 | #else /* USDT2 */ |
dcubed@3202 | 546 | DT_RETURN_MARK_DECL(FromReflectedField, jfieldID |
dcubed@3202 | 547 | , HOTSPOT_JNI_FROMREFLECTEDFIELD_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 548 | #endif /* USDT2 */ |
duke@435 | 549 | |
duke@435 | 550 | JNI_ENTRY(jfieldID, jni_FromReflectedField(JNIEnv *env, jobject field)) |
duke@435 | 551 | JNIWrapper("FromReflectedField"); |
dcubed@3202 | 552 | #ifndef USDT2 |
duke@435 | 553 | DTRACE_PROBE2(hotspot_jni, FromReflectedField__entry, env, field); |
dcubed@3202 | 554 | #else /* USDT2 */ |
dcubed@3202 | 555 | HOTSPOT_JNI_FROMREFLECTEDFIELD_ENTRY( |
dcubed@3202 | 556 | env, field); |
dcubed@3202 | 557 | #endif /* USDT2 */ |
duke@435 | 558 | jfieldID ret = NULL; |
duke@435 | 559 | DT_RETURN_MARK(FromReflectedField, jfieldID, (const jfieldID&)ret); |
duke@435 | 560 | |
duke@435 | 561 | // field is a handle to a java.lang.reflect.Field object |
duke@435 | 562 | oop reflected = JNIHandles::resolve_non_null(field); |
duke@435 | 563 | oop mirror = java_lang_reflect_Field::clazz(reflected); |
coleenp@4037 | 564 | Klass* k = java_lang_Class::as_Klass(mirror); |
duke@435 | 565 | int slot = java_lang_reflect_Field::slot(reflected); |
duke@435 | 566 | int modifiers = java_lang_reflect_Field::modifiers(reflected); |
duke@435 | 567 | |
duke@435 | 568 | KlassHandle k1(THREAD, k); |
duke@435 | 569 | // Make sure class is initialized before handing id's out to fields |
hseigel@4278 | 570 | k1()->initialize(CHECK_NULL); |
duke@435 | 571 | |
duke@435 | 572 | // First check if this is a static field |
duke@435 | 573 | if (modifiers & JVM_ACC_STATIC) { |
coleenp@4037 | 574 | intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot ); |
coleenp@4037 | 575 | JNIid* id = InstanceKlass::cast(k1())->jni_id_for(offset); |
duke@435 | 576 | assert(id != NULL, "corrupt Field object"); |
duke@435 | 577 | debug_only(id->set_is_static_field_id();) |
coleenp@4037 | 578 | // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass* |
duke@435 | 579 | ret = jfieldIDWorkaround::to_static_jfieldID(id); |
duke@435 | 580 | return ret; |
duke@435 | 581 | } |
duke@435 | 582 | |
duke@435 | 583 | // The slot is the index of the field description in the field-array |
duke@435 | 584 | // The jfieldID is the offset of the field within the object |
duke@435 | 585 | // It may also have hash bits for k, if VerifyJNIFields is turned on. |
coleenp@4037 | 586 | intptr_t offset = InstanceKlass::cast(k1())->field_offset( slot ); |
coleenp@4037 | 587 | assert(InstanceKlass::cast(k1())->contains_field_offset(offset), "stay within object"); |
duke@435 | 588 | ret = jfieldIDWorkaround::to_instance_jfieldID(k1(), offset); |
duke@435 | 589 | return ret; |
duke@435 | 590 | JNI_END |
duke@435 | 591 | |
dcubed@3202 | 592 | #ifndef USDT2 |
duke@435 | 593 | DT_RETURN_MARK_DECL(ToReflectedMethod, jobject); |
dcubed@3202 | 594 | #else /* USDT2 */ |
dcubed@3202 | 595 | DT_RETURN_MARK_DECL(ToReflectedMethod, jobject |
dcubed@3202 | 596 | , HOTSPOT_JNI_TOREFLECTEDMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 597 | #endif /* USDT2 */ |
duke@435 | 598 | |
duke@435 | 599 | JNI_ENTRY(jobject, jni_ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID method_id, jboolean isStatic)) |
duke@435 | 600 | JNIWrapper("ToReflectedMethod"); |
dcubed@3202 | 601 | #ifndef USDT2 |
duke@435 | 602 | DTRACE_PROBE4(hotspot_jni, ToReflectedMethod__entry, env, cls, method_id, isStatic); |
dcubed@3202 | 603 | #else /* USDT2 */ |
dcubed@3202 | 604 | HOTSPOT_JNI_TOREFLECTEDMETHOD_ENTRY( |
dcubed@3202 | 605 | env, cls, (uintptr_t) method_id, isStatic); |
dcubed@3202 | 606 | #endif /* USDT2 */ |
duke@435 | 607 | jobject ret = NULL; |
duke@435 | 608 | DT_RETURN_MARK(ToReflectedMethod, jobject, (const jobject&)ret); |
duke@435 | 609 | |
coleenp@4037 | 610 | methodHandle m (THREAD, Method::resolve_jmethod_id(method_id)); |
duke@435 | 611 | assert(m->is_static() == (isStatic != 0), "jni_ToReflectedMethod access flags doesn't match"); |
duke@435 | 612 | oop reflection_method; |
duke@435 | 613 | if (m->is_initializer()) { |
duke@435 | 614 | reflection_method = Reflection::new_constructor(m, CHECK_NULL); |
duke@435 | 615 | } else { |
duke@435 | 616 | reflection_method = Reflection::new_method(m, UseNewReflection, false, CHECK_NULL); |
duke@435 | 617 | } |
duke@435 | 618 | ret = JNIHandles::make_local(env, reflection_method); |
duke@435 | 619 | return ret; |
duke@435 | 620 | JNI_END |
duke@435 | 621 | |
dcubed@3202 | 622 | #ifndef USDT2 |
duke@435 | 623 | DT_RETURN_MARK_DECL(GetSuperclass, jclass); |
dcubed@3202 | 624 | #else /* USDT2 */ |
dcubed@3202 | 625 | DT_RETURN_MARK_DECL(GetSuperclass, jclass |
dcubed@3202 | 626 | , HOTSPOT_JNI_GETSUPERCLASS_RETURN(_ret_ref)); |
dcubed@3202 | 627 | #endif /* USDT2 */ |
duke@435 | 628 | |
duke@435 | 629 | JNI_ENTRY(jclass, jni_GetSuperclass(JNIEnv *env, jclass sub)) |
duke@435 | 630 | JNIWrapper("GetSuperclass"); |
dcubed@3202 | 631 | #ifndef USDT2 |
duke@435 | 632 | DTRACE_PROBE2(hotspot_jni, GetSuperclass__entry, env, sub); |
dcubed@3202 | 633 | #else /* USDT2 */ |
dcubed@3202 | 634 | HOTSPOT_JNI_GETSUPERCLASS_ENTRY( |
dcubed@3202 | 635 | env, sub); |
dcubed@3202 | 636 | #endif /* USDT2 */ |
duke@435 | 637 | jclass obj = NULL; |
duke@435 | 638 | DT_RETURN_MARK(GetSuperclass, jclass, (const jclass&)obj); |
duke@435 | 639 | |
duke@435 | 640 | oop mirror = JNIHandles::resolve_non_null(sub); |
duke@435 | 641 | // primitive classes return NULL |
duke@435 | 642 | if (java_lang_Class::is_primitive(mirror)) return NULL; |
duke@435 | 643 | |
duke@435 | 644 | // Rules of Class.getSuperClass as implemented by KLass::java_super: |
duke@435 | 645 | // arrays return Object |
duke@435 | 646 | // interfaces return NULL |
duke@435 | 647 | // proper classes return Klass::super() |
coleenp@4037 | 648 | Klass* k = java_lang_Class::as_Klass(mirror); |
hseigel@4278 | 649 | if (k->is_interface()) return NULL; |
duke@435 | 650 | |
duke@435 | 651 | // return mirror for superclass |
hseigel@4278 | 652 | Klass* super = k->java_super(); |
duke@435 | 653 | // super2 is the value computed by the compiler's getSuperClass intrinsic: |
hseigel@4278 | 654 | debug_only(Klass* super2 = ( k->oop_is_array() |
never@1577 | 655 | ? SystemDictionary::Object_klass() |
hseigel@4278 | 656 | : k->super() ) ); |
duke@435 | 657 | assert(super == super2, |
duke@435 | 658 | "java_super computation depends on interface, array, other super"); |
hseigel@4278 | 659 | obj = (super == NULL) ? NULL : (jclass) JNIHandles::make_local(super->java_mirror()); |
duke@435 | 660 | return obj; |
duke@435 | 661 | JNI_END |
duke@435 | 662 | |
duke@435 | 663 | JNI_QUICK_ENTRY(jboolean, jni_IsAssignableFrom(JNIEnv *env, jclass sub, jclass super)) |
duke@435 | 664 | JNIWrapper("IsSubclassOf"); |
dcubed@3202 | 665 | #ifndef USDT2 |
duke@435 | 666 | DTRACE_PROBE3(hotspot_jni, IsAssignableFrom__entry, env, sub, super); |
dcubed@3202 | 667 | #else /* USDT2 */ |
dcubed@3202 | 668 | HOTSPOT_JNI_ISASSIGNABLEFROM_ENTRY( |
dcubed@3202 | 669 | env, sub, super); |
dcubed@3202 | 670 | #endif /* USDT2 */ |
duke@435 | 671 | oop sub_mirror = JNIHandles::resolve_non_null(sub); |
duke@435 | 672 | oop super_mirror = JNIHandles::resolve_non_null(super); |
duke@435 | 673 | if (java_lang_Class::is_primitive(sub_mirror) || |
duke@435 | 674 | java_lang_Class::is_primitive(super_mirror)) { |
duke@435 | 675 | jboolean ret = (sub_mirror == super_mirror); |
dcubed@3202 | 676 | #ifndef USDT2 |
duke@435 | 677 | DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
dcubed@3202 | 678 | #else /* USDT2 */ |
dcubed@3202 | 679 | HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( |
dcubed@3202 | 680 | ret); |
dcubed@3202 | 681 | #endif /* USDT2 */ |
duke@435 | 682 | return ret; |
duke@435 | 683 | } |
coleenp@4037 | 684 | Klass* sub_klass = java_lang_Class::as_Klass(sub_mirror); |
coleenp@4037 | 685 | Klass* super_klass = java_lang_Class::as_Klass(super_mirror); |
duke@435 | 686 | assert(sub_klass != NULL && super_klass != NULL, "invalid arguments to jni_IsAssignableFrom"); |
hseigel@4278 | 687 | jboolean ret = sub_klass->is_subtype_of(super_klass) ? |
duke@435 | 688 | JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 689 | #ifndef USDT2 |
duke@435 | 690 | DTRACE_PROBE1(hotspot_jni, IsAssignableFrom__return, ret); |
dcubed@3202 | 691 | #else /* USDT2 */ |
dcubed@3202 | 692 | HOTSPOT_JNI_ISASSIGNABLEFROM_RETURN( |
dcubed@3202 | 693 | ret); |
dcubed@3202 | 694 | #endif /* USDT2 */ |
duke@435 | 695 | return ret; |
duke@435 | 696 | JNI_END |
duke@435 | 697 | |
dcubed@3202 | 698 | #ifndef USDT2 |
duke@435 | 699 | DT_RETURN_MARK_DECL(Throw, jint); |
dcubed@3202 | 700 | #else /* USDT2 */ |
dcubed@3202 | 701 | DT_RETURN_MARK_DECL(Throw, jint |
dcubed@3202 | 702 | , HOTSPOT_JNI_THROW_RETURN(_ret_ref)); |
dcubed@3202 | 703 | #endif /* USDT2 */ |
duke@435 | 704 | |
duke@435 | 705 | JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj)) |
duke@435 | 706 | JNIWrapper("Throw"); |
dcubed@3202 | 707 | #ifndef USDT2 |
duke@435 | 708 | DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj); |
dcubed@3202 | 709 | #else /* USDT2 */ |
dcubed@3202 | 710 | HOTSPOT_JNI_THROW_ENTRY( |
dcubed@3202 | 711 | env, obj); |
dcubed@3202 | 712 | #endif /* USDT2 */ |
duke@435 | 713 | jint ret = JNI_OK; |
duke@435 | 714 | DT_RETURN_MARK(Throw, jint, (const jint&)ret); |
duke@435 | 715 | |
duke@435 | 716 | THROW_OOP_(JNIHandles::resolve(obj), JNI_OK); |
duke@435 | 717 | ShouldNotReachHere(); |
duke@435 | 718 | JNI_END |
duke@435 | 719 | |
dcubed@3202 | 720 | #ifndef USDT2 |
duke@435 | 721 | DT_RETURN_MARK_DECL(ThrowNew, jint); |
dcubed@3202 | 722 | #else /* USDT2 */ |
dcubed@3202 | 723 | DT_RETURN_MARK_DECL(ThrowNew, jint |
dcubed@3202 | 724 | , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref)); |
dcubed@3202 | 725 | #endif /* USDT2 */ |
duke@435 | 726 | |
duke@435 | 727 | JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message)) |
duke@435 | 728 | JNIWrapper("ThrowNew"); |
dcubed@3202 | 729 | #ifndef USDT2 |
duke@435 | 730 | DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message); |
dcubed@3202 | 731 | #else /* USDT2 */ |
dcubed@3202 | 732 | HOTSPOT_JNI_THROWNEW_ENTRY( |
dcubed@3202 | 733 | env, clazz, (char *) message); |
dcubed@3202 | 734 | #endif /* USDT2 */ |
duke@435 | 735 | jint ret = JNI_OK; |
duke@435 | 736 | DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret); |
duke@435 | 737 | |
coleenp@4037 | 738 | InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
coleenp@2497 | 739 | Symbol* name = k->name(); |
duke@435 | 740 | Handle class_loader (THREAD, k->class_loader()); |
duke@435 | 741 | Handle protection_domain (THREAD, k->protection_domain()); |
duke@435 | 742 | THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK); |
duke@435 | 743 | ShouldNotReachHere(); |
duke@435 | 744 | JNI_END |
duke@435 | 745 | |
duke@435 | 746 | |
duke@435 | 747 | // JNI functions only transform a pending async exception to a synchronous |
duke@435 | 748 | // exception in ExceptionOccurred and ExceptionCheck calls, since |
duke@435 | 749 | // delivering an async exception in other places won't change the native |
duke@435 | 750 | // code's control flow and would be harmful when native code further calls |
duke@435 | 751 | // JNI functions with a pending exception. Async exception is also checked |
duke@435 | 752 | // during the call, so ExceptionOccurred/ExceptionCheck won't return |
duke@435 | 753 | // false but deliver the async exception at the very end during |
duke@435 | 754 | // state transition. |
duke@435 | 755 | |
duke@435 | 756 | static void jni_check_async_exceptions(JavaThread *thread) { |
duke@435 | 757 | assert(thread == Thread::current(), "must be itself"); |
duke@435 | 758 | thread->check_and_handle_async_exceptions(); |
duke@435 | 759 | } |
duke@435 | 760 | |
duke@435 | 761 | JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env)) |
duke@435 | 762 | JNIWrapper("ExceptionOccurred"); |
dcubed@3202 | 763 | #ifndef USDT2 |
duke@435 | 764 | DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__entry, env); |
dcubed@3202 | 765 | #else /* USDT2 */ |
dcubed@3202 | 766 | HOTSPOT_JNI_EXCEPTIONOCCURRED_ENTRY( |
dcubed@3202 | 767 | env); |
dcubed@3202 | 768 | #endif /* USDT2 */ |
duke@435 | 769 | jni_check_async_exceptions(thread); |
duke@435 | 770 | oop exception = thread->pending_exception(); |
duke@435 | 771 | jthrowable ret = (jthrowable) JNIHandles::make_local(env, exception); |
dcubed@3202 | 772 | #ifndef USDT2 |
duke@435 | 773 | DTRACE_PROBE1(hotspot_jni, ExceptionOccurred__return, ret); |
dcubed@3202 | 774 | #else /* USDT2 */ |
dcubed@3202 | 775 | HOTSPOT_JNI_EXCEPTIONOCCURRED_RETURN( |
dcubed@3202 | 776 | ret); |
dcubed@3202 | 777 | #endif /* USDT2 */ |
duke@435 | 778 | return ret; |
duke@435 | 779 | JNI_END |
duke@435 | 780 | |
duke@435 | 781 | |
duke@435 | 782 | JNI_ENTRY_NO_PRESERVE(void, jni_ExceptionDescribe(JNIEnv *env)) |
duke@435 | 783 | JNIWrapper("ExceptionDescribe"); |
dcubed@3202 | 784 | #ifndef USDT2 |
duke@435 | 785 | DTRACE_PROBE1(hotspot_jni, ExceptionDescribe__entry, env); |
dcubed@3202 | 786 | #else /* USDT2 */ |
dcubed@3202 | 787 | HOTSPOT_JNI_EXCEPTIONDESCRIBE_ENTRY( |
dcubed@3202 | 788 | env); |
dcubed@3202 | 789 | #endif /* USDT2 */ |
duke@435 | 790 | if (thread->has_pending_exception()) { |
duke@435 | 791 | Handle ex(thread, thread->pending_exception()); |
duke@435 | 792 | thread->clear_pending_exception(); |
never@1577 | 793 | if (ex->is_a(SystemDictionary::ThreadDeath_klass())) { |
duke@435 | 794 | // Don't print anything if we are being killed. |
duke@435 | 795 | } else { |
duke@435 | 796 | jio_fprintf(defaultStream::error_stream(), "Exception "); |
duke@435 | 797 | if (thread != NULL && thread->threadObj() != NULL) { |
duke@435 | 798 | ResourceMark rm(THREAD); |
duke@435 | 799 | jio_fprintf(defaultStream::error_stream(), |
duke@435 | 800 | "in thread \"%s\" ", thread->get_thread_name()); |
duke@435 | 801 | } |
never@1577 | 802 | if (ex->is_a(SystemDictionary::Throwable_klass())) { |
duke@435 | 803 | JavaValue result(T_VOID); |
duke@435 | 804 | JavaCalls::call_virtual(&result, |
duke@435 | 805 | ex, |
duke@435 | 806 | KlassHandle(THREAD, |
never@1577 | 807 | SystemDictionary::Throwable_klass()), |
coleenp@2497 | 808 | vmSymbols::printStackTrace_name(), |
coleenp@2497 | 809 | vmSymbols::void_method_signature(), |
duke@435 | 810 | THREAD); |
duke@435 | 811 | // If an exception is thrown in the call it gets thrown away. Not much |
duke@435 | 812 | // we can do with it. The native code that calls this, does not check |
duke@435 | 813 | // for the exception - hence, it might still be in the thread when DestroyVM gets |
duke@435 | 814 | // called, potentially causing a few asserts to trigger - since no pending exception |
duke@435 | 815 | // is expected. |
duke@435 | 816 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 817 | } else { |
duke@435 | 818 | ResourceMark rm(THREAD); |
duke@435 | 819 | jio_fprintf(defaultStream::error_stream(), |
duke@435 | 820 | ". Uncaught exception of type %s.", |
hseigel@4278 | 821 | ex->klass()->external_name()); |
duke@435 | 822 | } |
duke@435 | 823 | } |
duke@435 | 824 | } |
dcubed@3202 | 825 | #ifndef USDT2 |
duke@435 | 826 | DTRACE_PROBE(hotspot_jni, ExceptionDescribe__return); |
dcubed@3202 | 827 | #else /* USDT2 */ |
dcubed@3202 | 828 | HOTSPOT_JNI_EXCEPTIONDESCRIBE_RETURN( |
dcubed@3202 | 829 | ); |
dcubed@3202 | 830 | #endif /* USDT2 */ |
duke@435 | 831 | JNI_END |
duke@435 | 832 | |
duke@435 | 833 | |
duke@435 | 834 | JNI_QUICK_ENTRY(void, jni_ExceptionClear(JNIEnv *env)) |
duke@435 | 835 | JNIWrapper("ExceptionClear"); |
dcubed@3202 | 836 | #ifndef USDT2 |
duke@435 | 837 | DTRACE_PROBE1(hotspot_jni, ExceptionClear__entry, env); |
dcubed@3202 | 838 | #else /* USDT2 */ |
dcubed@3202 | 839 | HOTSPOT_JNI_EXCEPTIONCLEAR_ENTRY( |
dcubed@3202 | 840 | env); |
dcubed@3202 | 841 | #endif /* USDT2 */ |
duke@435 | 842 | |
duke@435 | 843 | // The jni code might be using this API to clear java thrown exception. |
duke@435 | 844 | // So just mark jvmti thread exception state as exception caught. |
duke@435 | 845 | JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); |
duke@435 | 846 | if (state != NULL && state->is_exception_detected()) { |
duke@435 | 847 | state->set_exception_caught(); |
duke@435 | 848 | } |
duke@435 | 849 | thread->clear_pending_exception(); |
dcubed@3202 | 850 | #ifndef USDT2 |
duke@435 | 851 | DTRACE_PROBE(hotspot_jni, ExceptionClear__return); |
dcubed@3202 | 852 | #else /* USDT2 */ |
dcubed@3202 | 853 | HOTSPOT_JNI_EXCEPTIONCLEAR_RETURN( |
dcubed@3202 | 854 | ); |
dcubed@3202 | 855 | #endif /* USDT2 */ |
duke@435 | 856 | JNI_END |
duke@435 | 857 | |
duke@435 | 858 | |
duke@435 | 859 | JNI_ENTRY(void, jni_FatalError(JNIEnv *env, const char *msg)) |
duke@435 | 860 | JNIWrapper("FatalError"); |
dcubed@3202 | 861 | #ifndef USDT2 |
duke@435 | 862 | DTRACE_PROBE2(hotspot_jni, FatalError__entry, env, msg); |
dcubed@3202 | 863 | #else /* USDT2 */ |
dcubed@3202 | 864 | HOTSPOT_JNI_FATALERROR_ENTRY( |
dcubed@3202 | 865 | env, (char *) msg); |
dcubed@3202 | 866 | #endif /* USDT2 */ |
duke@435 | 867 | tty->print_cr("FATAL ERROR in native method: %s", msg); |
duke@435 | 868 | thread->print_stack(); |
poonam@662 | 869 | os::abort(); // Dump core and abort |
duke@435 | 870 | JNI_END |
duke@435 | 871 | |
duke@435 | 872 | |
duke@435 | 873 | JNI_ENTRY(jint, jni_PushLocalFrame(JNIEnv *env, jint capacity)) |
duke@435 | 874 | JNIWrapper("PushLocalFrame"); |
dcubed@3202 | 875 | #ifndef USDT2 |
duke@435 | 876 | DTRACE_PROBE2(hotspot_jni, PushLocalFrame__entry, env, capacity); |
dcubed@3202 | 877 | #else /* USDT2 */ |
dcubed@3202 | 878 | HOTSPOT_JNI_PUSHLOCALFRAME_ENTRY( |
dcubed@3202 | 879 | env, capacity); |
dcubed@3202 | 880 | #endif /* USDT2 */ |
duke@435 | 881 | //%note jni_11 |
hseigel@5332 | 882 | if (capacity < 0 || capacity > MAX_REASONABLE_LOCAL_CAPACITY) { |
dcubed@3202 | 883 | #ifndef USDT2 |
duke@435 | 884 | DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, JNI_ERR); |
dcubed@3202 | 885 | #else /* USDT2 */ |
dcubed@3202 | 886 | HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( |
dcubed@3202 | 887 | (uint32_t)JNI_ERR); |
dcubed@3202 | 888 | #endif /* USDT2 */ |
duke@435 | 889 | return JNI_ERR; |
duke@435 | 890 | } |
duke@435 | 891 | JNIHandleBlock* old_handles = thread->active_handles(); |
duke@435 | 892 | JNIHandleBlock* new_handles = JNIHandleBlock::allocate_block(thread); |
duke@435 | 893 | assert(new_handles != NULL, "should not be NULL"); |
duke@435 | 894 | new_handles->set_pop_frame_link(old_handles); |
duke@435 | 895 | thread->set_active_handles(new_handles); |
duke@435 | 896 | jint ret = JNI_OK; |
dcubed@3202 | 897 | #ifndef USDT2 |
duke@435 | 898 | DTRACE_PROBE1(hotspot_jni, PushLocalFrame__return, ret); |
dcubed@3202 | 899 | #else /* USDT2 */ |
dcubed@3202 | 900 | HOTSPOT_JNI_PUSHLOCALFRAME_RETURN( |
dcubed@3202 | 901 | ret); |
dcubed@3202 | 902 | #endif /* USDT2 */ |
duke@435 | 903 | return ret; |
duke@435 | 904 | JNI_END |
duke@435 | 905 | |
duke@435 | 906 | |
duke@435 | 907 | JNI_ENTRY(jobject, jni_PopLocalFrame(JNIEnv *env, jobject result)) |
duke@435 | 908 | JNIWrapper("PopLocalFrame"); |
dcubed@3202 | 909 | #ifndef USDT2 |
duke@435 | 910 | DTRACE_PROBE2(hotspot_jni, PopLocalFrame__entry, env, result); |
dcubed@3202 | 911 | #else /* USDT2 */ |
dcubed@3202 | 912 | HOTSPOT_JNI_POPLOCALFRAME_ENTRY( |
dcubed@3202 | 913 | env, result); |
dcubed@3202 | 914 | #endif /* USDT2 */ |
duke@435 | 915 | //%note jni_11 |
duke@435 | 916 | Handle result_handle(thread, JNIHandles::resolve(result)); |
duke@435 | 917 | JNIHandleBlock* old_handles = thread->active_handles(); |
duke@435 | 918 | JNIHandleBlock* new_handles = old_handles->pop_frame_link(); |
duke@435 | 919 | if (new_handles != NULL) { |
duke@435 | 920 | // As a sanity check we only release the handle blocks if the pop_frame_link is not NULL. |
duke@435 | 921 | // This way code will still work if PopLocalFrame is called without a corresponding |
duke@435 | 922 | // PushLocalFrame call. Note that we set the pop_frame_link to NULL explicitly, otherwise |
duke@435 | 923 | // the release_block call will release the blocks. |
duke@435 | 924 | thread->set_active_handles(new_handles); |
duke@435 | 925 | old_handles->set_pop_frame_link(NULL); // clear link we won't release new_handles below |
duke@435 | 926 | JNIHandleBlock::release_block(old_handles, thread); // may block |
duke@435 | 927 | result = JNIHandles::make_local(thread, result_handle()); |
duke@435 | 928 | } |
dcubed@3202 | 929 | #ifndef USDT2 |
duke@435 | 930 | DTRACE_PROBE1(hotspot_jni, PopLocalFrame__return, result); |
dcubed@3202 | 931 | #else /* USDT2 */ |
dcubed@3202 | 932 | HOTSPOT_JNI_POPLOCALFRAME_RETURN( |
dcubed@3202 | 933 | result); |
dcubed@3202 | 934 | #endif /* USDT2 */ |
duke@435 | 935 | return result; |
duke@435 | 936 | JNI_END |
duke@435 | 937 | |
duke@435 | 938 | |
duke@435 | 939 | JNI_ENTRY(jobject, jni_NewGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 940 | JNIWrapper("NewGlobalRef"); |
dcubed@3202 | 941 | #ifndef USDT2 |
duke@435 | 942 | DTRACE_PROBE2(hotspot_jni, NewGlobalRef__entry, env, ref); |
dcubed@3202 | 943 | #else /* USDT2 */ |
dcubed@3202 | 944 | HOTSPOT_JNI_NEWGLOBALREF_ENTRY( |
dcubed@3202 | 945 | env, ref); |
dcubed@3202 | 946 | #endif /* USDT2 */ |
duke@435 | 947 | Handle ref_handle(thread, JNIHandles::resolve(ref)); |
duke@435 | 948 | jobject ret = JNIHandles::make_global(ref_handle); |
dcubed@3202 | 949 | #ifndef USDT2 |
duke@435 | 950 | DTRACE_PROBE1(hotspot_jni, NewGlobalRef__return, ret); |
dcubed@3202 | 951 | #else /* USDT2 */ |
dcubed@3202 | 952 | HOTSPOT_JNI_NEWGLOBALREF_RETURN( |
dcubed@3202 | 953 | ret); |
dcubed@3202 | 954 | #endif /* USDT2 */ |
duke@435 | 955 | return ret; |
duke@435 | 956 | JNI_END |
duke@435 | 957 | |
duke@435 | 958 | // Must be JNI_ENTRY (with HandleMark) |
duke@435 | 959 | JNI_ENTRY_NO_PRESERVE(void, jni_DeleteGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 960 | JNIWrapper("DeleteGlobalRef"); |
dcubed@3202 | 961 | #ifndef USDT2 |
duke@435 | 962 | DTRACE_PROBE2(hotspot_jni, DeleteGlobalRef__entry, env, ref); |
dcubed@3202 | 963 | #else /* USDT2 */ |
dcubed@3202 | 964 | HOTSPOT_JNI_DELETEGLOBALREF_ENTRY( |
dcubed@3202 | 965 | env, ref); |
dcubed@3202 | 966 | #endif /* USDT2 */ |
duke@435 | 967 | JNIHandles::destroy_global(ref); |
dcubed@3202 | 968 | #ifndef USDT2 |
duke@435 | 969 | DTRACE_PROBE(hotspot_jni, DeleteGlobalRef__return); |
dcubed@3202 | 970 | #else /* USDT2 */ |
dcubed@3202 | 971 | HOTSPOT_JNI_DELETEGLOBALREF_RETURN( |
dcubed@3202 | 972 | ); |
dcubed@3202 | 973 | #endif /* USDT2 */ |
duke@435 | 974 | JNI_END |
duke@435 | 975 | |
duke@435 | 976 | JNI_QUICK_ENTRY(void, jni_DeleteLocalRef(JNIEnv *env, jobject obj)) |
duke@435 | 977 | JNIWrapper("DeleteLocalRef"); |
dcubed@3202 | 978 | #ifndef USDT2 |
duke@435 | 979 | DTRACE_PROBE2(hotspot_jni, DeleteLocalRef__entry, env, obj); |
dcubed@3202 | 980 | #else /* USDT2 */ |
dcubed@3202 | 981 | HOTSPOT_JNI_DELETELOCALREF_ENTRY( |
dcubed@3202 | 982 | env, obj); |
dcubed@3202 | 983 | #endif /* USDT2 */ |
duke@435 | 984 | JNIHandles::destroy_local(obj); |
dcubed@3202 | 985 | #ifndef USDT2 |
duke@435 | 986 | DTRACE_PROBE(hotspot_jni, DeleteLocalRef__return); |
dcubed@3202 | 987 | #else /* USDT2 */ |
dcubed@3202 | 988 | HOTSPOT_JNI_DELETELOCALREF_RETURN( |
dcubed@3202 | 989 | ); |
dcubed@3202 | 990 | #endif /* USDT2 */ |
duke@435 | 991 | JNI_END |
duke@435 | 992 | |
duke@435 | 993 | JNI_QUICK_ENTRY(jboolean, jni_IsSameObject(JNIEnv *env, jobject r1, jobject r2)) |
duke@435 | 994 | JNIWrapper("IsSameObject"); |
dcubed@3202 | 995 | #ifndef USDT2 |
duke@435 | 996 | DTRACE_PROBE3(hotspot_jni, IsSameObject__entry, env, r1, r2); |
dcubed@3202 | 997 | #else /* USDT2 */ |
dcubed@3202 | 998 | HOTSPOT_JNI_ISSAMEOBJECT_ENTRY( |
dcubed@3202 | 999 | env, r1, r2); |
dcubed@3202 | 1000 | #endif /* USDT2 */ |
duke@435 | 1001 | oop a = JNIHandles::resolve(r1); |
duke@435 | 1002 | oop b = JNIHandles::resolve(r2); |
duke@435 | 1003 | jboolean ret = (a == b) ? JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 1004 | #ifndef USDT2 |
duke@435 | 1005 | DTRACE_PROBE1(hotspot_jni, IsSameObject__return, ret); |
dcubed@3202 | 1006 | #else /* USDT2 */ |
dcubed@3202 | 1007 | HOTSPOT_JNI_ISSAMEOBJECT_RETURN( |
dcubed@3202 | 1008 | ret); |
dcubed@3202 | 1009 | #endif /* USDT2 */ |
duke@435 | 1010 | return ret; |
duke@435 | 1011 | JNI_END |
duke@435 | 1012 | |
duke@435 | 1013 | |
duke@435 | 1014 | JNI_ENTRY(jobject, jni_NewLocalRef(JNIEnv *env, jobject ref)) |
duke@435 | 1015 | JNIWrapper("NewLocalRef"); |
dcubed@3202 | 1016 | #ifndef USDT2 |
duke@435 | 1017 | DTRACE_PROBE2(hotspot_jni, NewLocalRef__entry, env, ref); |
dcubed@3202 | 1018 | #else /* USDT2 */ |
dcubed@3202 | 1019 | HOTSPOT_JNI_NEWLOCALREF_ENTRY( |
dcubed@3202 | 1020 | env, ref); |
dcubed@3202 | 1021 | #endif /* USDT2 */ |
duke@435 | 1022 | jobject ret = JNIHandles::make_local(env, JNIHandles::resolve(ref)); |
dcubed@3202 | 1023 | #ifndef USDT2 |
duke@435 | 1024 | DTRACE_PROBE1(hotspot_jni, NewLocalRef__return, ret); |
dcubed@3202 | 1025 | #else /* USDT2 */ |
dcubed@3202 | 1026 | HOTSPOT_JNI_NEWLOCALREF_RETURN( |
dcubed@3202 | 1027 | ret); |
dcubed@3202 | 1028 | #endif /* USDT2 */ |
duke@435 | 1029 | return ret; |
duke@435 | 1030 | JNI_END |
duke@435 | 1031 | |
duke@435 | 1032 | JNI_LEAF(jint, jni_EnsureLocalCapacity(JNIEnv *env, jint capacity)) |
duke@435 | 1033 | JNIWrapper("EnsureLocalCapacity"); |
dcubed@3202 | 1034 | #ifndef USDT2 |
duke@435 | 1035 | DTRACE_PROBE2(hotspot_jni, EnsureLocalCapacity__entry, env, capacity); |
dcubed@3202 | 1036 | #else /* USDT2 */ |
dcubed@3202 | 1037 | HOTSPOT_JNI_ENSURELOCALCAPACITY_ENTRY( |
dcubed@3202 | 1038 | env, capacity); |
dcubed@3202 | 1039 | #endif /* USDT2 */ |
duke@435 | 1040 | jint ret; |
duke@435 | 1041 | if (capacity >= 0 && capacity <= MAX_REASONABLE_LOCAL_CAPACITY) { |
duke@435 | 1042 | ret = JNI_OK; |
duke@435 | 1043 | } else { |
duke@435 | 1044 | ret = JNI_ERR; |
duke@435 | 1045 | } |
dcubed@3202 | 1046 | #ifndef USDT2 |
duke@435 | 1047 | DTRACE_PROBE1(hotspot_jni, EnsureLocalCapacity__return, ret); |
dcubed@3202 | 1048 | #else /* USDT2 */ |
dcubed@3202 | 1049 | HOTSPOT_JNI_ENSURELOCALCAPACITY_RETURN( |
dcubed@3202 | 1050 | ret); |
dcubed@3202 | 1051 | #endif /* USDT2 */ |
duke@435 | 1052 | return ret; |
duke@435 | 1053 | JNI_END |
duke@435 | 1054 | |
duke@435 | 1055 | // Return the Handle Type |
duke@435 | 1056 | JNI_LEAF(jobjectRefType, jni_GetObjectRefType(JNIEnv *env, jobject obj)) |
duke@435 | 1057 | JNIWrapper("GetObjectRefType"); |
dcubed@3202 | 1058 | #ifndef USDT2 |
duke@435 | 1059 | DTRACE_PROBE2(hotspot_jni, GetObjectRefType__entry, env, obj); |
dcubed@3202 | 1060 | #else /* USDT2 */ |
dcubed@3202 | 1061 | HOTSPOT_JNI_GETOBJECTREFTYPE_ENTRY( |
dcubed@3202 | 1062 | env, obj); |
dcubed@3202 | 1063 | #endif /* USDT2 */ |
duke@435 | 1064 | jobjectRefType ret; |
duke@435 | 1065 | if (JNIHandles::is_local_handle(thread, obj) || |
duke@435 | 1066 | JNIHandles::is_frame_handle(thread, obj)) |
duke@435 | 1067 | ret = JNILocalRefType; |
duke@435 | 1068 | else if (JNIHandles::is_global_handle(obj)) |
duke@435 | 1069 | ret = JNIGlobalRefType; |
duke@435 | 1070 | else if (JNIHandles::is_weak_global_handle(obj)) |
duke@435 | 1071 | ret = JNIWeakGlobalRefType; |
duke@435 | 1072 | else |
duke@435 | 1073 | ret = JNIInvalidRefType; |
dcubed@3202 | 1074 | #ifndef USDT2 |
duke@435 | 1075 | DTRACE_PROBE1(hotspot_jni, GetObjectRefType__return, ret); |
dcubed@3202 | 1076 | #else /* USDT2 */ |
dcubed@3202 | 1077 | HOTSPOT_JNI_GETOBJECTREFTYPE_RETURN( |
dcubed@3202 | 1078 | (void *) ret); |
dcubed@3202 | 1079 | #endif /* USDT2 */ |
duke@435 | 1080 | return ret; |
duke@435 | 1081 | JNI_END |
duke@435 | 1082 | |
duke@435 | 1083 | |
duke@435 | 1084 | class JNI_ArgumentPusher : public SignatureIterator { |
duke@435 | 1085 | protected: |
duke@435 | 1086 | JavaCallArguments* _arguments; |
duke@435 | 1087 | |
duke@435 | 1088 | virtual void get_bool () = 0; |
duke@435 | 1089 | virtual void get_char () = 0; |
duke@435 | 1090 | virtual void get_short () = 0; |
duke@435 | 1091 | virtual void get_byte () = 0; |
duke@435 | 1092 | virtual void get_int () = 0; |
duke@435 | 1093 | virtual void get_long () = 0; |
duke@435 | 1094 | virtual void get_float () = 0; |
duke@435 | 1095 | virtual void get_double () = 0; |
duke@435 | 1096 | virtual void get_object () = 0; |
duke@435 | 1097 | |
coleenp@2497 | 1098 | JNI_ArgumentPusher(Symbol* signature) : SignatureIterator(signature) { |
duke@435 | 1099 | this->_return_type = T_ILLEGAL; |
duke@435 | 1100 | _arguments = NULL; |
duke@435 | 1101 | } |
duke@435 | 1102 | |
duke@435 | 1103 | public: |
duke@435 | 1104 | virtual void iterate( uint64_t fingerprint ) = 0; |
duke@435 | 1105 | |
duke@435 | 1106 | void set_java_argument_object(JavaCallArguments *arguments) { _arguments = arguments; } |
duke@435 | 1107 | |
duke@435 | 1108 | inline void do_bool() { if (!is_return_type()) get_bool(); } |
duke@435 | 1109 | inline void do_char() { if (!is_return_type()) get_char(); } |
duke@435 | 1110 | inline void do_short() { if (!is_return_type()) get_short(); } |
duke@435 | 1111 | inline void do_byte() { if (!is_return_type()) get_byte(); } |
duke@435 | 1112 | inline void do_int() { if (!is_return_type()) get_int(); } |
duke@435 | 1113 | inline void do_long() { if (!is_return_type()) get_long(); } |
duke@435 | 1114 | inline void do_float() { if (!is_return_type()) get_float(); } |
duke@435 | 1115 | inline void do_double() { if (!is_return_type()) get_double(); } |
duke@435 | 1116 | inline void do_object(int begin, int end) { if (!is_return_type()) get_object(); } |
duke@435 | 1117 | inline void do_array(int begin, int end) { if (!is_return_type()) get_object(); } // do_array uses get_object -- there is no get_array |
duke@435 | 1118 | inline void do_void() { } |
duke@435 | 1119 | |
duke@435 | 1120 | JavaCallArguments* arguments() { return _arguments; } |
duke@435 | 1121 | void push_receiver(Handle h) { _arguments->push_oop(h); } |
duke@435 | 1122 | }; |
duke@435 | 1123 | |
duke@435 | 1124 | |
duke@435 | 1125 | class JNI_ArgumentPusherVaArg : public JNI_ArgumentPusher { |
duke@435 | 1126 | protected: |
duke@435 | 1127 | va_list _ap; |
duke@435 | 1128 | |
duke@435 | 1129 | inline void get_bool() { _arguments->push_int(va_arg(_ap, jint)); } // bool is coerced to int when using va_arg |
duke@435 | 1130 | inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg |
duke@435 | 1131 | inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg |
duke@435 | 1132 | inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg |
duke@435 | 1133 | inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); } |
duke@435 | 1134 | |
duke@435 | 1135 | // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests |
duke@435 | 1136 | |
duke@435 | 1137 | inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); } |
duke@435 | 1138 | inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg |
duke@435 | 1139 | inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); } |
duke@435 | 1140 | inline void get_object() { jobject l = va_arg(_ap, jobject); |
duke@435 | 1141 | _arguments->push_oop(Handle((oop *)l, false)); } |
duke@435 | 1142 | |
duke@435 | 1143 | inline void set_ap(va_list rap) { |
duke@435 | 1144 | #ifdef va_copy |
duke@435 | 1145 | va_copy(_ap, rap); |
duke@435 | 1146 | #elif defined (__va_copy) |
duke@435 | 1147 | __va_copy(_ap, rap); |
duke@435 | 1148 | #else |
duke@435 | 1149 | _ap = rap; |
duke@435 | 1150 | #endif |
duke@435 | 1151 | } |
duke@435 | 1152 | |
duke@435 | 1153 | public: |
coleenp@2497 | 1154 | JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap) |
coleenp@2497 | 1155 | : JNI_ArgumentPusher(signature) { |
duke@435 | 1156 | set_ap(rap); |
duke@435 | 1157 | } |
coleenp@2497 | 1158 | JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap) |
coleenp@4037 | 1159 | : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) { |
duke@435 | 1160 | set_ap(rap); |
duke@435 | 1161 | } |
duke@435 | 1162 | |
duke@435 | 1163 | // Optimized path if we have the bitvector form of signature |
duke@435 | 1164 | void iterate( uint64_t fingerprint ) { |
duke@435 | 1165 | if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate();// Must be too many arguments |
duke@435 | 1166 | else { |
duke@435 | 1167 | _return_type = (BasicType)((fingerprint >> static_feature_size) & |
duke@435 | 1168 | result_feature_mask); |
duke@435 | 1169 | |
duke@435 | 1170 | assert(fingerprint, "Fingerprint should not be 0"); |
duke@435 | 1171 | fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
duke@435 | 1172 | while ( 1 ) { |
duke@435 | 1173 | switch ( fingerprint & parameter_feature_mask ) { |
duke@435 | 1174 | case bool_parm: |
duke@435 | 1175 | case char_parm: |
duke@435 | 1176 | case short_parm: |
duke@435 | 1177 | case byte_parm: |
duke@435 | 1178 | case int_parm: |
duke@435 | 1179 | get_int(); |
duke@435 | 1180 | break; |
duke@435 | 1181 | case obj_parm: |
duke@435 | 1182 | get_object(); |
duke@435 | 1183 | break; |
duke@435 | 1184 | case long_parm: |
duke@435 | 1185 | get_long(); |
duke@435 | 1186 | break; |
duke@435 | 1187 | case float_parm: |
duke@435 | 1188 | get_float(); |
duke@435 | 1189 | break; |
duke@435 | 1190 | case double_parm: |
duke@435 | 1191 | get_double(); |
duke@435 | 1192 | break; |
duke@435 | 1193 | case done_parm: |
duke@435 | 1194 | return; |
duke@435 | 1195 | break; |
duke@435 | 1196 | default: |
duke@435 | 1197 | ShouldNotReachHere(); |
duke@435 | 1198 | break; |
duke@435 | 1199 | } |
duke@435 | 1200 | fingerprint >>= parameter_feature_size; |
duke@435 | 1201 | } |
duke@435 | 1202 | } |
duke@435 | 1203 | } |
duke@435 | 1204 | }; |
duke@435 | 1205 | |
duke@435 | 1206 | |
duke@435 | 1207 | class JNI_ArgumentPusherArray : public JNI_ArgumentPusher { |
duke@435 | 1208 | protected: |
duke@435 | 1209 | const jvalue *_ap; |
duke@435 | 1210 | |
duke@435 | 1211 | inline void get_bool() { _arguments->push_int((jint)(_ap++)->z); } |
duke@435 | 1212 | inline void get_char() { _arguments->push_int((jint)(_ap++)->c); } |
duke@435 | 1213 | inline void get_short() { _arguments->push_int((jint)(_ap++)->s); } |
duke@435 | 1214 | inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); } |
duke@435 | 1215 | inline void get_int() { _arguments->push_int((jint)(_ap++)->i); } |
duke@435 | 1216 | |
duke@435 | 1217 | inline void get_long() { _arguments->push_long((_ap++)->j); } |
duke@435 | 1218 | inline void get_float() { _arguments->push_float((_ap++)->f); } |
duke@435 | 1219 | inline void get_double() { _arguments->push_double((_ap++)->d);} |
duke@435 | 1220 | inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); } |
duke@435 | 1221 | |
duke@435 | 1222 | inline void set_ap(const jvalue *rap) { _ap = rap; } |
duke@435 | 1223 | |
duke@435 | 1224 | public: |
coleenp@2497 | 1225 | JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap) |
coleenp@2497 | 1226 | : JNI_ArgumentPusher(signature) { |
duke@435 | 1227 | set_ap(rap); |
duke@435 | 1228 | } |
coleenp@2497 | 1229 | JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap) |
coleenp@4037 | 1230 | : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) { |
duke@435 | 1231 | set_ap(rap); |
duke@435 | 1232 | } |
duke@435 | 1233 | |
duke@435 | 1234 | // Optimized path if we have the bitvector form of signature |
duke@435 | 1235 | void iterate( uint64_t fingerprint ) { |
duke@435 | 1236 | if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments |
duke@435 | 1237 | else { |
duke@435 | 1238 | _return_type = (BasicType)((fingerprint >> static_feature_size) & |
duke@435 | 1239 | result_feature_mask); |
duke@435 | 1240 | assert(fingerprint, "Fingerprint should not be 0"); |
duke@435 | 1241 | fingerprint = fingerprint >> (static_feature_size + result_feature_size); |
duke@435 | 1242 | while ( 1 ) { |
duke@435 | 1243 | switch ( fingerprint & parameter_feature_mask ) { |
duke@435 | 1244 | case bool_parm: |
duke@435 | 1245 | get_bool(); |
duke@435 | 1246 | break; |
duke@435 | 1247 | case char_parm: |
duke@435 | 1248 | get_char(); |
duke@435 | 1249 | break; |
duke@435 | 1250 | case short_parm: |
duke@435 | 1251 | get_short(); |
duke@435 | 1252 | break; |
duke@435 | 1253 | case byte_parm: |
duke@435 | 1254 | get_byte(); |
duke@435 | 1255 | break; |
duke@435 | 1256 | case int_parm: |
duke@435 | 1257 | get_int(); |
duke@435 | 1258 | break; |
duke@435 | 1259 | case obj_parm: |
duke@435 | 1260 | get_object(); |
duke@435 | 1261 | break; |
duke@435 | 1262 | case long_parm: |
duke@435 | 1263 | get_long(); |
duke@435 | 1264 | break; |
duke@435 | 1265 | case float_parm: |
duke@435 | 1266 | get_float(); |
duke@435 | 1267 | break; |
duke@435 | 1268 | case double_parm: |
duke@435 | 1269 | get_double(); |
duke@435 | 1270 | break; |
duke@435 | 1271 | case done_parm: |
duke@435 | 1272 | return; |
duke@435 | 1273 | break; |
duke@435 | 1274 | default: |
duke@435 | 1275 | ShouldNotReachHere(); |
duke@435 | 1276 | break; |
duke@435 | 1277 | } |
duke@435 | 1278 | fingerprint >>= parameter_feature_size; |
duke@435 | 1279 | } |
duke@435 | 1280 | } |
duke@435 | 1281 | } |
duke@435 | 1282 | }; |
duke@435 | 1283 | |
duke@435 | 1284 | |
duke@435 | 1285 | enum JNICallType { |
duke@435 | 1286 | JNI_STATIC, |
duke@435 | 1287 | JNI_VIRTUAL, |
duke@435 | 1288 | JNI_NONVIRTUAL |
duke@435 | 1289 | }; |
duke@435 | 1290 | |
duke@435 | 1291 | |
duke@435 | 1292 | |
duke@435 | 1293 | static void jni_invoke_static(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { |
coleenp@4037 | 1294 | methodHandle method(THREAD, Method::resolve_jmethod_id(method_id)); |
duke@435 | 1295 | |
duke@435 | 1296 | // Create object to hold arguments for the JavaCall, and associate it with |
duke@435 | 1297 | // the jni parser |
duke@435 | 1298 | ResourceMark rm(THREAD); |
duke@435 | 1299 | int number_of_parameters = method->size_of_parameters(); |
duke@435 | 1300 | JavaCallArguments java_args(number_of_parameters); |
duke@435 | 1301 | args->set_java_argument_object(&java_args); |
duke@435 | 1302 | |
duke@435 | 1303 | assert(method->is_static(), "method should be static"); |
duke@435 | 1304 | |
duke@435 | 1305 | // Fill out JavaCallArguments object |
coleenp@2497 | 1306 | args->iterate( Fingerprinter(method).fingerprint() ); |
duke@435 | 1307 | // Initialize result type |
duke@435 | 1308 | result->set_type(args->get_ret_type()); |
duke@435 | 1309 | |
duke@435 | 1310 | // Invoke the method. Result is returned as oop. |
duke@435 | 1311 | JavaCalls::call(result, method, &java_args, CHECK); |
duke@435 | 1312 | |
duke@435 | 1313 | // Convert result |
duke@435 | 1314 | if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { |
duke@435 | 1315 | result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); |
duke@435 | 1316 | } |
duke@435 | 1317 | } |
duke@435 | 1318 | |
duke@435 | 1319 | |
duke@435 | 1320 | static void jni_invoke_nonstatic(JNIEnv *env, JavaValue* result, jobject receiver, JNICallType call_type, jmethodID method_id, JNI_ArgumentPusher *args, TRAPS) { |
duke@435 | 1321 | oop recv = JNIHandles::resolve(receiver); |
duke@435 | 1322 | if (recv == NULL) { |
duke@435 | 1323 | THROW(vmSymbols::java_lang_NullPointerException()); |
duke@435 | 1324 | } |
duke@435 | 1325 | Handle h_recv(THREAD, recv); |
duke@435 | 1326 | |
duke@435 | 1327 | int number_of_parameters; |
coleenp@4037 | 1328 | Method* selected_method; |
duke@435 | 1329 | { |
coleenp@4037 | 1330 | Method* m = Method::resolve_jmethod_id(method_id); |
duke@435 | 1331 | number_of_parameters = m->size_of_parameters(); |
coleenp@4037 | 1332 | Klass* holder = m->method_holder(); |
hseigel@4278 | 1333 | if (!(holder)->is_interface()) { |
duke@435 | 1334 | // non-interface call -- for that little speed boost, don't handlize |
duke@435 | 1335 | debug_only(No_Safepoint_Verifier nosafepoint;) |
duke@435 | 1336 | if (call_type == JNI_VIRTUAL) { |
duke@435 | 1337 | // jni_GetMethodID makes sure class is linked and initialized |
duke@435 | 1338 | // so m should have a valid vtable index. |
duke@435 | 1339 | int vtbl_index = m->vtable_index(); |
coleenp@4037 | 1340 | if (vtbl_index != Method::nonvirtual_vtable_index) { |
coleenp@4037 | 1341 | Klass* k = h_recv->klass(); |
duke@435 | 1342 | // k might be an arrayKlassOop but all vtables start at |
duke@435 | 1343 | // the same place. The cast is to avoid virtual call and assertion. |
coleenp@4037 | 1344 | InstanceKlass *ik = (InstanceKlass*)k; |
duke@435 | 1345 | selected_method = ik->method_at_vtable(vtbl_index); |
duke@435 | 1346 | } else { |
duke@435 | 1347 | // final method |
duke@435 | 1348 | selected_method = m; |
duke@435 | 1349 | } |
duke@435 | 1350 | } else { |
duke@435 | 1351 | // JNI_NONVIRTUAL call |
duke@435 | 1352 | selected_method = m; |
duke@435 | 1353 | } |
duke@435 | 1354 | } else { |
duke@435 | 1355 | // interface call |
duke@435 | 1356 | KlassHandle h_holder(THREAD, holder); |
duke@435 | 1357 | |
duke@435 | 1358 | int itbl_index = m->cached_itable_index(); |
duke@435 | 1359 | if (itbl_index == -1) { |
duke@435 | 1360 | itbl_index = klassItable::compute_itable_index(m); |
duke@435 | 1361 | m->set_cached_itable_index(itbl_index); |
duke@435 | 1362 | // the above may have grabbed a lock, 'm' and anything non-handlized can't be used again |
duke@435 | 1363 | } |
coleenp@4037 | 1364 | Klass* k = h_recv->klass(); |
coleenp@4037 | 1365 | selected_method = InstanceKlass::cast(k)->method_at_itable(h_holder(), itbl_index, CHECK); |
duke@435 | 1366 | } |
duke@435 | 1367 | } |
duke@435 | 1368 | |
duke@435 | 1369 | methodHandle method(THREAD, selected_method); |
duke@435 | 1370 | |
duke@435 | 1371 | // Create object to hold arguments for the JavaCall, and associate it with |
duke@435 | 1372 | // the jni parser |
duke@435 | 1373 | ResourceMark rm(THREAD); |
duke@435 | 1374 | JavaCallArguments java_args(number_of_parameters); |
duke@435 | 1375 | args->set_java_argument_object(&java_args); |
duke@435 | 1376 | |
duke@435 | 1377 | // handle arguments |
duke@435 | 1378 | assert(!method->is_static(), "method should not be static"); |
duke@435 | 1379 | args->push_receiver(h_recv); // Push jobject handle |
duke@435 | 1380 | |
duke@435 | 1381 | // Fill out JavaCallArguments object |
coleenp@2497 | 1382 | args->iterate( Fingerprinter(method).fingerprint() ); |
duke@435 | 1383 | // Initialize result type |
duke@435 | 1384 | result->set_type(args->get_ret_type()); |
duke@435 | 1385 | |
duke@435 | 1386 | // Invoke the method. Result is returned as oop. |
duke@435 | 1387 | JavaCalls::call(result, method, &java_args, CHECK); |
duke@435 | 1388 | |
duke@435 | 1389 | // Convert result |
duke@435 | 1390 | if (result->get_type() == T_OBJECT || result->get_type() == T_ARRAY) { |
duke@435 | 1391 | result->set_jobject(JNIHandles::make_local(env, (oop) result->get_jobject())); |
duke@435 | 1392 | } |
duke@435 | 1393 | } |
duke@435 | 1394 | |
duke@435 | 1395 | |
duke@435 | 1396 | static instanceOop alloc_object(jclass clazz, TRAPS) { |
coleenp@4037 | 1397 | KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
hseigel@4278 | 1398 | k()->check_valid_for_instantiation(false, CHECK_NULL); |
coleenp@4037 | 1399 | InstanceKlass::cast(k())->initialize(CHECK_NULL); |
coleenp@4037 | 1400 | instanceOop ih = InstanceKlass::cast(k())->allocate_instance(THREAD); |
duke@435 | 1401 | return ih; |
duke@435 | 1402 | } |
duke@435 | 1403 | |
dcubed@3202 | 1404 | #ifndef USDT2 |
duke@435 | 1405 | DT_RETURN_MARK_DECL(AllocObject, jobject); |
dcubed@3202 | 1406 | #else /* USDT2 */ |
dcubed@3202 | 1407 | DT_RETURN_MARK_DECL(AllocObject, jobject |
dcubed@3202 | 1408 | , HOTSPOT_JNI_ALLOCOBJECT_RETURN(_ret_ref)); |
dcubed@3202 | 1409 | #endif /* USDT2 */ |
duke@435 | 1410 | |
duke@435 | 1411 | JNI_ENTRY(jobject, jni_AllocObject(JNIEnv *env, jclass clazz)) |
duke@435 | 1412 | JNIWrapper("AllocObject"); |
duke@435 | 1413 | |
dcubed@3202 | 1414 | #ifndef USDT2 |
duke@435 | 1415 | DTRACE_PROBE2(hotspot_jni, AllocObject__entry, env, clazz); |
dcubed@3202 | 1416 | #else /* USDT2 */ |
dcubed@3202 | 1417 | HOTSPOT_JNI_ALLOCOBJECT_ENTRY( |
dcubed@3202 | 1418 | env, clazz); |
dcubed@3202 | 1419 | #endif /* USDT2 */ |
duke@435 | 1420 | jobject ret = NULL; |
duke@435 | 1421 | DT_RETURN_MARK(AllocObject, jobject, (const jobject&)ret); |
duke@435 | 1422 | |
duke@435 | 1423 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1424 | ret = JNIHandles::make_local(env, i); |
duke@435 | 1425 | return ret; |
duke@435 | 1426 | JNI_END |
duke@435 | 1427 | |
dcubed@3202 | 1428 | #ifndef USDT2 |
duke@435 | 1429 | DT_RETURN_MARK_DECL(NewObjectA, jobject); |
dcubed@3202 | 1430 | #else /* USDT2 */ |
dcubed@3202 | 1431 | DT_RETURN_MARK_DECL(NewObjectA, jobject |
dcubed@3202 | 1432 | , HOTSPOT_JNI_NEWOBJECTA_RETURN(_ret_ref)); |
dcubed@3202 | 1433 | #endif /* USDT2 */ |
duke@435 | 1434 | |
duke@435 | 1435 | JNI_ENTRY(jobject, jni_NewObjectA(JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args)) |
duke@435 | 1436 | JNIWrapper("NewObjectA"); |
dcubed@3202 | 1437 | #ifndef USDT2 |
duke@435 | 1438 | DTRACE_PROBE3(hotspot_jni, NewObjectA__entry, env, clazz, methodID); |
dcubed@3202 | 1439 | #else /* USDT2 */ |
dcubed@3202 | 1440 | HOTSPOT_JNI_NEWOBJECTA_ENTRY( |
dcubed@3202 | 1441 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1442 | #endif /* USDT2 */ |
duke@435 | 1443 | jobject obj = NULL; |
duke@435 | 1444 | DT_RETURN_MARK(NewObjectA, jobject, (const jobject)obj); |
duke@435 | 1445 | |
duke@435 | 1446 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1447 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1448 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1449 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 1450 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1451 | return obj; |
duke@435 | 1452 | JNI_END |
duke@435 | 1453 | |
dcubed@3202 | 1454 | #ifndef USDT2 |
duke@435 | 1455 | DT_RETURN_MARK_DECL(NewObjectV, jobject); |
dcubed@3202 | 1456 | #else /* USDT2 */ |
dcubed@3202 | 1457 | DT_RETURN_MARK_DECL(NewObjectV, jobject |
dcubed@3202 | 1458 | , HOTSPOT_JNI_NEWOBJECTV_RETURN(_ret_ref)); |
dcubed@3202 | 1459 | #endif /* USDT2 */ |
duke@435 | 1460 | |
duke@435 | 1461 | JNI_ENTRY(jobject, jni_NewObjectV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)) |
duke@435 | 1462 | JNIWrapper("NewObjectV"); |
dcubed@3202 | 1463 | #ifndef USDT2 |
duke@435 | 1464 | DTRACE_PROBE3(hotspot_jni, NewObjectV__entry, env, clazz, methodID); |
dcubed@3202 | 1465 | #else /* USDT2 */ |
dcubed@3202 | 1466 | HOTSPOT_JNI_NEWOBJECTV_ENTRY( |
dcubed@3202 | 1467 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1468 | #endif /* USDT2 */ |
duke@435 | 1469 | jobject obj = NULL; |
duke@435 | 1470 | DT_RETURN_MARK(NewObjectV, jobject, (const jobject&)obj); |
duke@435 | 1471 | |
duke@435 | 1472 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1473 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1474 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1475 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1476 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1477 | return obj; |
duke@435 | 1478 | JNI_END |
duke@435 | 1479 | |
dcubed@3202 | 1480 | #ifndef USDT2 |
duke@435 | 1481 | DT_RETURN_MARK_DECL(NewObject, jobject); |
dcubed@3202 | 1482 | #else /* USDT2 */ |
dcubed@3202 | 1483 | DT_RETURN_MARK_DECL(NewObject, jobject |
dcubed@3202 | 1484 | , HOTSPOT_JNI_NEWOBJECT_RETURN(_ret_ref)); |
dcubed@3202 | 1485 | #endif /* USDT2 */ |
duke@435 | 1486 | |
duke@435 | 1487 | JNI_ENTRY(jobject, jni_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)) |
duke@435 | 1488 | JNIWrapper("NewObject"); |
dcubed@3202 | 1489 | #ifndef USDT2 |
duke@435 | 1490 | DTRACE_PROBE3(hotspot_jni, NewObject__entry, env, clazz, methodID); |
dcubed@3202 | 1491 | #else /* USDT2 */ |
dcubed@3202 | 1492 | HOTSPOT_JNI_NEWOBJECT_ENTRY( |
dcubed@3202 | 1493 | env, clazz, (uintptr_t) methodID); |
dcubed@3202 | 1494 | #endif /* USDT2 */ |
duke@435 | 1495 | jobject obj = NULL; |
duke@435 | 1496 | DT_RETURN_MARK(NewObject, jobject, (const jobject&)obj); |
duke@435 | 1497 | |
duke@435 | 1498 | instanceOop i = alloc_object(clazz, CHECK_NULL); |
duke@435 | 1499 | obj = JNIHandles::make_local(env, i); |
duke@435 | 1500 | va_list args; |
duke@435 | 1501 | va_start(args, methodID); |
duke@435 | 1502 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1503 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1504 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_NULL); |
duke@435 | 1505 | va_end(args); |
duke@435 | 1506 | return obj; |
duke@435 | 1507 | JNI_END |
duke@435 | 1508 | |
duke@435 | 1509 | |
duke@435 | 1510 | JNI_ENTRY(jclass, jni_GetObjectClass(JNIEnv *env, jobject obj)) |
duke@435 | 1511 | JNIWrapper("GetObjectClass"); |
dcubed@3202 | 1512 | #ifndef USDT2 |
duke@435 | 1513 | DTRACE_PROBE2(hotspot_jni, GetObjectClass__entry, env, obj); |
dcubed@3202 | 1514 | #else /* USDT2 */ |
dcubed@3202 | 1515 | HOTSPOT_JNI_GETOBJECTCLASS_ENTRY( |
dcubed@3202 | 1516 | env, obj); |
dcubed@3202 | 1517 | #endif /* USDT2 */ |
coleenp@4037 | 1518 | Klass* k = JNIHandles::resolve_non_null(obj)->klass(); |
duke@435 | 1519 | jclass ret = |
hseigel@4278 | 1520 | (jclass) JNIHandles::make_local(env, k->java_mirror()); |
dcubed@3202 | 1521 | #ifndef USDT2 |
duke@435 | 1522 | DTRACE_PROBE1(hotspot_jni, GetObjectClass__return, ret); |
dcubed@3202 | 1523 | #else /* USDT2 */ |
dcubed@3202 | 1524 | HOTSPOT_JNI_GETOBJECTCLASS_RETURN( |
dcubed@3202 | 1525 | ret); |
dcubed@3202 | 1526 | #endif /* USDT2 */ |
duke@435 | 1527 | return ret; |
duke@435 | 1528 | JNI_END |
duke@435 | 1529 | |
duke@435 | 1530 | JNI_QUICK_ENTRY(jboolean, jni_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)) |
duke@435 | 1531 | JNIWrapper("IsInstanceOf"); |
dcubed@3202 | 1532 | #ifndef USDT2 |
duke@435 | 1533 | DTRACE_PROBE3(hotspot_jni, IsInstanceOf__entry, env, obj, clazz); |
dcubed@3202 | 1534 | #else /* USDT2 */ |
dcubed@3202 | 1535 | HOTSPOT_JNI_ISINSTANCEOF_ENTRY( |
dcubed@3202 | 1536 | env, obj, clazz); |
dcubed@3202 | 1537 | #endif /* USDT2 */ |
duke@435 | 1538 | jboolean ret = JNI_TRUE; |
duke@435 | 1539 | if (obj != NULL) { |
duke@435 | 1540 | ret = JNI_FALSE; |
coleenp@4037 | 1541 | Klass* k = java_lang_Class::as_Klass( |
duke@435 | 1542 | JNIHandles::resolve_non_null(clazz)); |
duke@435 | 1543 | if (k != NULL) { |
duke@435 | 1544 | ret = JNIHandles::resolve_non_null(obj)->is_a(k) ? JNI_TRUE : JNI_FALSE; |
duke@435 | 1545 | } |
duke@435 | 1546 | } |
dcubed@3202 | 1547 | #ifndef USDT2 |
duke@435 | 1548 | DTRACE_PROBE1(hotspot_jni, IsInstanceOf__return, ret); |
dcubed@3202 | 1549 | #else /* USDT2 */ |
dcubed@3202 | 1550 | HOTSPOT_JNI_ISINSTANCEOF_RETURN( |
dcubed@3202 | 1551 | ret); |
dcubed@3202 | 1552 | #endif /* USDT2 */ |
duke@435 | 1553 | return ret; |
duke@435 | 1554 | JNI_END |
duke@435 | 1555 | |
duke@435 | 1556 | |
duke@435 | 1557 | static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str, |
duke@435 | 1558 | const char *sig, bool is_static, TRAPS) { |
duke@435 | 1559 | // %%%% This code should probably just call into a method in the LinkResolver |
duke@435 | 1560 | // |
duke@435 | 1561 | // The class should have been loaded (we have an instance of the class |
duke@435 | 1562 | // passed in) so the method and signature should already be in the symbol |
duke@435 | 1563 | // table. If they're not there, the method doesn't exist. |
coleenp@2497 | 1564 | const char *name_to_probe = (name_str == NULL) |
coleenp@2497 | 1565 | ? vmSymbols::object_initializer_name()->as_C_string() |
coleenp@2497 | 1566 | : name_str; |
coleenp@2497 | 1567 | TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe)); |
coleenp@2497 | 1568 | TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 1569 | |
coleenp@2497 | 1570 | if (name == NULL || signature == NULL) { |
duke@435 | 1571 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1572 | } |
duke@435 | 1573 | |
duke@435 | 1574 | // Throw a NoSuchMethodError exception if we have an instance of a |
duke@435 | 1575 | // primitive java.lang.Class |
duke@435 | 1576 | if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) { |
duke@435 | 1577 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1578 | } |
duke@435 | 1579 | |
duke@435 | 1580 | KlassHandle klass(THREAD, |
coleenp@4037 | 1581 | java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 1582 | |
duke@435 | 1583 | // Make sure class is linked and initialized before handing id's out to |
coleenp@4037 | 1584 | // Method*s. |
hseigel@4278 | 1585 | klass()->initialize(CHECK_NULL); |
duke@435 | 1586 | |
coleenp@4037 | 1587 | Method* m; |
coleenp@2497 | 1588 | if (name == vmSymbols::object_initializer_name() || |
coleenp@2497 | 1589 | name == vmSymbols::class_initializer_name()) { |
duke@435 | 1590 | // Never search superclasses for constructors |
duke@435 | 1591 | if (klass->oop_is_instance()) { |
coleenp@4037 | 1592 | m = InstanceKlass::cast(klass())->find_method(name, signature); |
duke@435 | 1593 | } else { |
duke@435 | 1594 | m = NULL; |
duke@435 | 1595 | } |
duke@435 | 1596 | } else { |
coleenp@2497 | 1597 | m = klass->lookup_method(name, signature); |
duke@435 | 1598 | // Look up interfaces |
duke@435 | 1599 | if (m == NULL && klass->oop_is_instance()) { |
coleenp@4037 | 1600 | m = InstanceKlass::cast(klass())->lookup_method_in_all_interfaces(name, |
coleenp@2497 | 1601 | signature); |
duke@435 | 1602 | } |
duke@435 | 1603 | } |
duke@435 | 1604 | if (m == NULL || (m->is_static() != is_static)) { |
duke@435 | 1605 | THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str); |
duke@435 | 1606 | } |
duke@435 | 1607 | return m->jmethod_id(); |
duke@435 | 1608 | } |
duke@435 | 1609 | |
duke@435 | 1610 | |
duke@435 | 1611 | JNI_ENTRY(jmethodID, jni_GetMethodID(JNIEnv *env, jclass clazz, |
duke@435 | 1612 | const char *name, const char *sig)) |
duke@435 | 1613 | JNIWrapper("GetMethodID"); |
dcubed@3202 | 1614 | #ifndef USDT2 |
duke@435 | 1615 | DTRACE_PROBE4(hotspot_jni, GetMethodID__entry, env, clazz, name, sig); |
dcubed@3202 | 1616 | #else /* USDT2 */ |
dcubed@3202 | 1617 | HOTSPOT_JNI_GETMETHODID_ENTRY( |
dcubed@3202 | 1618 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 1619 | #endif /* USDT2 */ |
duke@435 | 1620 | jmethodID ret = get_method_id(env, clazz, name, sig, false, thread); |
dcubed@3202 | 1621 | #ifndef USDT2 |
duke@435 | 1622 | DTRACE_PROBE1(hotspot_jni, GetMethodID__return, ret); |
dcubed@3202 | 1623 | #else /* USDT2 */ |
dcubed@3202 | 1624 | HOTSPOT_JNI_GETMETHODID_RETURN( |
dcubed@3202 | 1625 | (uintptr_t) ret); |
dcubed@3202 | 1626 | #endif /* USDT2 */ |
duke@435 | 1627 | return ret; |
duke@435 | 1628 | JNI_END |
duke@435 | 1629 | |
duke@435 | 1630 | |
duke@435 | 1631 | JNI_ENTRY(jmethodID, jni_GetStaticMethodID(JNIEnv *env, jclass clazz, |
duke@435 | 1632 | const char *name, const char *sig)) |
duke@435 | 1633 | JNIWrapper("GetStaticMethodID"); |
dcubed@3202 | 1634 | #ifndef USDT2 |
duke@435 | 1635 | DTRACE_PROBE4(hotspot_jni, GetStaticMethodID__entry, env, clazz, name, sig); |
dcubed@3202 | 1636 | #else /* USDT2 */ |
dcubed@3202 | 1637 | HOTSPOT_JNI_GETSTATICMETHODID_ENTRY( |
dcubed@3202 | 1638 | env, (char *) clazz, (char *) name, (char *)sig); |
dcubed@3202 | 1639 | #endif /* USDT2 */ |
duke@435 | 1640 | jmethodID ret = get_method_id(env, clazz, name, sig, true, thread); |
dcubed@3202 | 1641 | #ifndef USDT2 |
duke@435 | 1642 | DTRACE_PROBE1(hotspot_jni, GetStaticMethodID__return, ret); |
dcubed@3202 | 1643 | #else /* USDT2 */ |
dcubed@3202 | 1644 | HOTSPOT_JNI_GETSTATICMETHODID_RETURN( |
dcubed@3202 | 1645 | (uintptr_t) ret); |
dcubed@3202 | 1646 | #endif /* USDT2 */ |
duke@435 | 1647 | return ret; |
duke@435 | 1648 | JNI_END |
duke@435 | 1649 | |
duke@435 | 1650 | |
duke@435 | 1651 | |
duke@435 | 1652 | // |
duke@435 | 1653 | // Calling Methods |
duke@435 | 1654 | // |
duke@435 | 1655 | |
dcubed@3202 | 1656 | #ifndef USDT2 |
duke@435 | 1657 | #define DEFINE_CALLMETHOD(ResultType, Result, Tag) \ |
duke@435 | 1658 | \ |
duke@435 | 1659 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType);\ |
duke@435 | 1660 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType);\ |
duke@435 | 1661 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType);\ |
duke@435 | 1662 | \ |
duke@435 | 1663 | JNI_ENTRY(ResultType, \ |
duke@435 | 1664 | jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ |
duke@435 | 1665 | JNIWrapper("Call" XSTR(Result) "Method"); \ |
duke@435 | 1666 | \ |
dcubed@3202 | 1667 | DTRACE_PROBE3(hotspot_jni, Call##Result##Method__entry, env, obj, methodID); \ |
duke@435 | 1668 | ResultType ret = 0;\ |
duke@435 | 1669 | DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ |
duke@435 | 1670 | (const ResultType&)ret);\ |
duke@435 | 1671 | \ |
duke@435 | 1672 | va_list args; \ |
duke@435 | 1673 | va_start(args, methodID); \ |
duke@435 | 1674 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1675 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1676 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1677 | va_end(args); \ |
duke@435 | 1678 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1679 | return ret;\ |
duke@435 | 1680 | JNI_END \ |
duke@435 | 1681 | \ |
duke@435 | 1682 | \ |
duke@435 | 1683 | JNI_ENTRY(ResultType, \ |
duke@435 | 1684 | jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ |
duke@435 | 1685 | JNIWrapper("Call" XSTR(Result) "MethodV"); \ |
duke@435 | 1686 | \ |
dcubed@3202 | 1687 | DTRACE_PROBE3(hotspot_jni, Call##Result##MethodV__entry, env, obj, methodID); \ |
duke@435 | 1688 | ResultType ret = 0;\ |
duke@435 | 1689 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ |
duke@435 | 1690 | (const ResultType&)ret);\ |
duke@435 | 1691 | \ |
duke@435 | 1692 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1693 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1694 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1695 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1696 | return ret;\ |
duke@435 | 1697 | JNI_END \ |
duke@435 | 1698 | \ |
duke@435 | 1699 | \ |
duke@435 | 1700 | JNI_ENTRY(ResultType, \ |
duke@435 | 1701 | jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 1702 | JNIWrapper("Call" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 1703 | DTRACE_PROBE3(hotspot_jni, Call##Result##MethodA__entry, env, obj, methodID); \ |
duke@435 | 1704 | ResultType ret = 0;\ |
duke@435 | 1705 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ |
duke@435 | 1706 | (const ResultType&)ret);\ |
duke@435 | 1707 | \ |
duke@435 | 1708 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1709 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 1710 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1711 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1712 | return ret;\ |
duke@435 | 1713 | JNI_END |
duke@435 | 1714 | |
duke@435 | 1715 | // the runtime type of subword integral basic types is integer |
duke@435 | 1716 | DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 1717 | DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 1718 | DEFINE_CALLMETHOD(jchar, Char, T_CHAR) |
duke@435 | 1719 | DEFINE_CALLMETHOD(jshort, Short, T_SHORT) |
duke@435 | 1720 | |
duke@435 | 1721 | DEFINE_CALLMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 1722 | DEFINE_CALLMETHOD(jint, Int, T_INT) |
duke@435 | 1723 | DEFINE_CALLMETHOD(jlong, Long, T_LONG) |
duke@435 | 1724 | DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 1725 | DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 1726 | |
duke@435 | 1727 | DT_VOID_RETURN_MARK_DECL(CallVoidMethod); |
duke@435 | 1728 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodV); |
duke@435 | 1729 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodA); |
duke@435 | 1730 | |
dcubed@3202 | 1731 | #else /* USDT2 */ |
dcubed@3202 | 1732 | |
dcubed@3202 | 1733 | #define DEFINE_CALLMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 1734 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1735 | \ |
dcubed@3202 | 1736 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##Method, ResultType \ |
dcubed@3202 | 1737 | , ReturnProbe); \ |
dcubed@3202 | 1738 | \ |
dcubed@3202 | 1739 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1740 | jni_Call##Result##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...)) \ |
dcubed@3202 | 1741 | JNIWrapper("Call" XSTR(Result) "Method"); \ |
dcubed@3202 | 1742 | \ |
dcubed@3202 | 1743 | EntryProbe; \ |
dcubed@3202 | 1744 | ResultType ret = 0;\ |
dcubed@3202 | 1745 | DT_RETURN_MARK_FOR(Result, Call##Result##Method, ResultType, \ |
dcubed@3202 | 1746 | (const ResultType&)ret);\ |
dcubed@3202 | 1747 | \ |
dcubed@3202 | 1748 | va_list args; \ |
dcubed@3202 | 1749 | va_start(args, methodID); \ |
dcubed@3202 | 1750 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1751 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 1752 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1753 | va_end(args); \ |
dcubed@3202 | 1754 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1755 | return ret;\ |
dcubed@3202 | 1756 | JNI_END |
dcubed@3202 | 1757 | |
dcubed@3202 | 1758 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1759 | DEFINE_CALLMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1760 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1761 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1762 | DEFINE_CALLMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 1763 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1764 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1765 | DEFINE_CALLMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 1766 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1767 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1768 | DEFINE_CALLMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 1769 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1770 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1771 | |
dcubed@3202 | 1772 | DEFINE_CALLMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 1773 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1774 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1775 | DEFINE_CALLMETHOD(jint, Int, T_INT, |
dcubed@3202 | 1776 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1777 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1778 | DEFINE_CALLMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 1779 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1780 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1781 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1782 | DEFINE_CALLMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 1783 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1784 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1785 | DEFINE_CALLMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1786 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1787 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1788 | |
dcubed@3202 | 1789 | #define DEFINE_CALLMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 1790 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1791 | \ |
dcubed@3202 | 1792 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodV, ResultType \ |
dcubed@3202 | 1793 | , ReturnProbe); \ |
dcubed@3202 | 1794 | \ |
dcubed@3202 | 1795 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1796 | jni_Call##Result##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 1797 | JNIWrapper("Call" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 1798 | \ |
dcubed@3202 | 1799 | EntryProbe;\ |
dcubed@3202 | 1800 | ResultType ret = 0;\ |
dcubed@3202 | 1801 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodV, ResultType, \ |
dcubed@3202 | 1802 | (const ResultType&)ret);\ |
dcubed@3202 | 1803 | \ |
dcubed@3202 | 1804 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1805 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 1806 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1807 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1808 | return ret;\ |
dcubed@3202 | 1809 | JNI_END |
dcubed@3202 | 1810 | |
dcubed@3202 | 1811 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1812 | DEFINE_CALLMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1813 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1814 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1815 | DEFINE_CALLMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 1816 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1817 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1818 | DEFINE_CALLMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 1819 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1820 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1821 | DEFINE_CALLMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 1822 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1823 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1824 | |
dcubed@3202 | 1825 | DEFINE_CALLMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 1826 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1827 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1828 | DEFINE_CALLMETHODV(jint, Int, T_INT, |
dcubed@3202 | 1829 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1830 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1831 | DEFINE_CALLMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 1832 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1833 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1834 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1835 | DEFINE_CALLMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 1836 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1837 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1838 | DEFINE_CALLMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1839 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1840 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1841 | |
dcubed@3202 | 1842 | #define DEFINE_CALLMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 1843 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 1844 | \ |
dcubed@3202 | 1845 | DT_RETURN_MARK_DECL_FOR(Result, Call##Result##MethodA, ResultType \ |
dcubed@3202 | 1846 | , ReturnProbe); \ |
dcubed@3202 | 1847 | \ |
dcubed@3202 | 1848 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 1849 | jni_Call##Result##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 1850 | JNIWrapper("Call" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 1851 | EntryProbe; \ |
dcubed@3202 | 1852 | ResultType ret = 0;\ |
dcubed@3202 | 1853 | DT_RETURN_MARK_FOR(Result, Call##Result##MethodA, ResultType, \ |
dcubed@3202 | 1854 | (const ResultType&)ret);\ |
dcubed@3202 | 1855 | \ |
dcubed@3202 | 1856 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 1857 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 1858 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 1859 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 1860 | return ret;\ |
dcubed@3202 | 1861 | JNI_END |
dcubed@3202 | 1862 | |
dcubed@3202 | 1863 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 1864 | DEFINE_CALLMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 1865 | , HOTSPOT_JNI_CALLBOOLEANMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1866 | HOTSPOT_JNI_CALLBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1867 | DEFINE_CALLMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 1868 | , HOTSPOT_JNI_CALLBYTEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1869 | HOTSPOT_JNI_CALLBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1870 | DEFINE_CALLMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 1871 | , HOTSPOT_JNI_CALLCHARMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1872 | HOTSPOT_JNI_CALLCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1873 | DEFINE_CALLMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 1874 | , HOTSPOT_JNI_CALLSHORTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1875 | HOTSPOT_JNI_CALLSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1876 | |
dcubed@3202 | 1877 | DEFINE_CALLMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 1878 | , HOTSPOT_JNI_CALLOBJECTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1879 | HOTSPOT_JNI_CALLOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1880 | DEFINE_CALLMETHODA(jint, Int, T_INT, |
dcubed@3202 | 1881 | HOTSPOT_JNI_CALLINTMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1882 | HOTSPOT_JNI_CALLINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1883 | DEFINE_CALLMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 1884 | , HOTSPOT_JNI_CALLLONGMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1885 | HOTSPOT_JNI_CALLLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 1886 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 1887 | DEFINE_CALLMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 1888 | , HOTSPOT_JNI_CALLFLOATMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1889 | HOTSPOT_JNI_CALLFLOATMETHOD_RETURN()) |
dcubed@3202 | 1890 | DEFINE_CALLMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 1891 | , HOTSPOT_JNI_CALLDOUBLEMETHOD_ENTRY(env, obj, (uintptr_t)methodID), |
dcubed@3202 | 1892 | HOTSPOT_JNI_CALLDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 1893 | |
dcubed@3202 | 1894 | DT_VOID_RETURN_MARK_DECL(CallVoidMethod, HOTSPOT_JNI_CALLVOIDMETHOD_RETURN()); |
dcubed@3202 | 1895 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodV, HOTSPOT_JNI_CALLVOIDMETHODV_RETURN()); |
dcubed@3202 | 1896 | DT_VOID_RETURN_MARK_DECL(CallVoidMethodA, HOTSPOT_JNI_CALLVOIDMETHODA_RETURN()); |
dcubed@3202 | 1897 | |
dcubed@3202 | 1898 | #endif /* USDT2 */ |
dcubed@3202 | 1899 | |
duke@435 | 1900 | JNI_ENTRY(void, jni_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)) |
duke@435 | 1901 | JNIWrapper("CallVoidMethod"); |
dcubed@3202 | 1902 | #ifndef USDT2 |
duke@435 | 1903 | DTRACE_PROBE3(hotspot_jni, CallVoidMethod__entry, env, obj, methodID); |
dcubed@3202 | 1904 | #else /* USDT2 */ |
dcubed@3202 | 1905 | HOTSPOT_JNI_CALLVOIDMETHOD_ENTRY( |
dcubed@3202 | 1906 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1907 | #endif /* USDT2 */ |
duke@435 | 1908 | DT_VOID_RETURN_MARK(CallVoidMethod); |
duke@435 | 1909 | |
duke@435 | 1910 | va_list args; |
duke@435 | 1911 | va_start(args, methodID); |
duke@435 | 1912 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1913 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1914 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1915 | va_end(args); |
duke@435 | 1916 | JNI_END |
duke@435 | 1917 | |
duke@435 | 1918 | |
duke@435 | 1919 | JNI_ENTRY(void, jni_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)) |
duke@435 | 1920 | JNIWrapper("CallVoidMethodV"); |
dcubed@3202 | 1921 | #ifndef USDT2 |
duke@435 | 1922 | DTRACE_PROBE3(hotspot_jni, CallVoidMethodV__entry, env, obj, methodID); |
dcubed@3202 | 1923 | #else /* USDT2 */ |
dcubed@3202 | 1924 | HOTSPOT_JNI_CALLVOIDMETHODV_ENTRY( |
dcubed@3202 | 1925 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1926 | #endif /* USDT2 */ |
duke@435 | 1927 | DT_VOID_RETURN_MARK(CallVoidMethodV); |
duke@435 | 1928 | |
duke@435 | 1929 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1930 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 1931 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1932 | JNI_END |
duke@435 | 1933 | |
duke@435 | 1934 | |
duke@435 | 1935 | JNI_ENTRY(void, jni_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args)) |
duke@435 | 1936 | JNIWrapper("CallVoidMethodA"); |
dcubed@3202 | 1937 | #ifndef USDT2 |
duke@435 | 1938 | DTRACE_PROBE3(hotspot_jni, CallVoidMethodA__entry, env, obj, methodID); |
dcubed@3202 | 1939 | #else /* USDT2 */ |
dcubed@3202 | 1940 | HOTSPOT_JNI_CALLVOIDMETHODA_ENTRY( |
dcubed@3202 | 1941 | env, obj, (uintptr_t) methodID); |
dcubed@3202 | 1942 | #endif /* USDT2 */ |
duke@435 | 1943 | DT_VOID_RETURN_MARK(CallVoidMethodA); |
duke@435 | 1944 | |
duke@435 | 1945 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 1946 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 1947 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_VIRTUAL, methodID, &ap, CHECK); |
duke@435 | 1948 | JNI_END |
duke@435 | 1949 | |
duke@435 | 1950 | |
dcubed@3202 | 1951 | #ifndef USDT2 |
duke@435 | 1952 | #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag) \ |
duke@435 | 1953 | \ |
duke@435 | 1954 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType);\ |
duke@435 | 1955 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType);\ |
duke@435 | 1956 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType);\ |
duke@435 | 1957 | \ |
duke@435 | 1958 | JNI_ENTRY(ResultType, \ |
duke@435 | 1959 | jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ |
duke@435 | 1960 | JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ |
duke@435 | 1961 | \ |
duke@435 | 1962 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##Method__entry, env, obj, cls, methodID);\ |
duke@435 | 1963 | ResultType ret;\ |
duke@435 | 1964 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ |
duke@435 | 1965 | (const ResultType&)ret);\ |
duke@435 | 1966 | \ |
duke@435 | 1967 | va_list args; \ |
duke@435 | 1968 | va_start(args, methodID); \ |
duke@435 | 1969 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1970 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1971 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1972 | va_end(args); \ |
duke@435 | 1973 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1974 | return ret;\ |
duke@435 | 1975 | JNI_END \ |
duke@435 | 1976 | \ |
duke@435 | 1977 | JNI_ENTRY(ResultType, \ |
duke@435 | 1978 | jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ |
duke@435 | 1979 | JNIWrapper("CallNonvitual" XSTR(Result) "#MethodV"); \ |
duke@435 | 1980 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodV__entry, env, obj, cls, methodID);\ |
duke@435 | 1981 | ResultType ret;\ |
duke@435 | 1982 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ |
duke@435 | 1983 | (const ResultType&)ret);\ |
duke@435 | 1984 | \ |
duke@435 | 1985 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 1986 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 1987 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 1988 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 1989 | return ret;\ |
duke@435 | 1990 | JNI_END \ |
duke@435 | 1991 | \ |
duke@435 | 1992 | JNI_ENTRY(ResultType, \ |
duke@435 | 1993 | jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 1994 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ |
duke@435 | 1995 | DTRACE_PROBE4(hotspot_jni, CallNonvirtual##Result##MethodA__entry, env, obj, cls, methodID);\ |
duke@435 | 1996 | ResultType ret;\ |
duke@435 | 1997 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ |
duke@435 | 1998 | (const ResultType&)ret);\ |
duke@435 | 1999 | \ |
duke@435 | 2000 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2001 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 2002 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
duke@435 | 2003 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2004 | return ret;\ |
duke@435 | 2005 | JNI_END |
duke@435 | 2006 | |
duke@435 | 2007 | // the runtime type of subword integral basic types is integer |
duke@435 | 2008 | DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 2009 | DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 2010 | DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR) |
duke@435 | 2011 | DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT) |
duke@435 | 2012 | |
duke@435 | 2013 | DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 2014 | DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT) |
duke@435 | 2015 | DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG) |
duke@435 | 2016 | DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 2017 | DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 2018 | |
duke@435 | 2019 | |
duke@435 | 2020 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod); |
duke@435 | 2021 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV); |
duke@435 | 2022 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA); |
duke@435 | 2023 | |
dcubed@3202 | 2024 | #else /* USDT2 */ |
dcubed@3202 | 2025 | |
dcubed@3202 | 2026 | #define DEFINE_CALLNONVIRTUALMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 2027 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2028 | \ |
dcubed@3202 | 2029 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##Method, ResultType \ |
dcubed@3202 | 2030 | , ReturnProbe);\ |
dcubed@3202 | 2031 | \ |
dcubed@3202 | 2032 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2033 | jni_CallNonvirtual##Result##Method(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) \ |
dcubed@3202 | 2034 | JNIWrapper("CallNonvitual" XSTR(Result) "Method"); \ |
dcubed@3202 | 2035 | \ |
dcubed@3202 | 2036 | EntryProbe;\ |
dcubed@3202 | 2037 | ResultType ret;\ |
dcubed@3202 | 2038 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##Method, ResultType, \ |
dcubed@3202 | 2039 | (const ResultType&)ret);\ |
dcubed@3202 | 2040 | \ |
dcubed@3202 | 2041 | va_list args; \ |
dcubed@3202 | 2042 | va_start(args, methodID); \ |
dcubed@3202 | 2043 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2044 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2045 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2046 | va_end(args); \ |
dcubed@3202 | 2047 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2048 | return ret;\ |
dcubed@3202 | 2049 | JNI_END |
dcubed@3202 | 2050 | |
dcubed@3202 | 2051 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2052 | DEFINE_CALLNONVIRTUALMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2053 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2054 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2055 | DEFINE_CALLNONVIRTUALMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 2056 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2057 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2058 | DEFINE_CALLNONVIRTUALMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 2059 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2060 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2061 | DEFINE_CALLNONVIRTUALMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 2062 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2063 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2064 | |
dcubed@3202 | 2065 | DEFINE_CALLNONVIRTUALMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 2066 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2067 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2068 | DEFINE_CALLNONVIRTUALMETHOD(jint, Int, T_INT |
dcubed@3202 | 2069 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2070 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2071 | DEFINE_CALLNONVIRTUALMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 2072 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2073 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2074 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHOD_RETURN(_ret_ref)) |
dcubed@3202 | 2075 | DEFINE_CALLNONVIRTUALMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 2076 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2077 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHOD_RETURN()) |
dcubed@3202 | 2078 | DEFINE_CALLNONVIRTUALMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2079 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2080 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHOD_RETURN()) |
dcubed@3202 | 2081 | |
dcubed@3202 | 2082 | #define DEFINE_CALLNONVIRTUALMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 2083 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2084 | \ |
dcubed@3202 | 2085 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodV, ResultType \ |
dcubed@3202 | 2086 | , ReturnProbe);\ |
dcubed@3202 | 2087 | \ |
dcubed@3202 | 2088 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2089 | jni_CallNonvirtual##Result##MethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 2090 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 2091 | \ |
dcubed@3202 | 2092 | EntryProbe;\ |
dcubed@3202 | 2093 | ResultType ret;\ |
dcubed@3202 | 2094 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodV, ResultType, \ |
dcubed@3202 | 2095 | (const ResultType&)ret);\ |
dcubed@3202 | 2096 | \ |
dcubed@3202 | 2097 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2098 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2099 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2100 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2101 | return ret;\ |
dcubed@3202 | 2102 | JNI_END |
dcubed@3202 | 2103 | |
dcubed@3202 | 2104 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2105 | DEFINE_CALLNONVIRTUALMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2106 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2107 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2108 | DEFINE_CALLNONVIRTUALMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 2109 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2110 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2111 | DEFINE_CALLNONVIRTUALMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 2112 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2113 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2114 | DEFINE_CALLNONVIRTUALMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 2115 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2116 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2117 | |
dcubed@3202 | 2118 | DEFINE_CALLNONVIRTUALMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 2119 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2120 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2121 | DEFINE_CALLNONVIRTUALMETHODV(jint, Int, T_INT |
dcubed@3202 | 2122 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2123 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2124 | DEFINE_CALLNONVIRTUALMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 2125 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2126 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2127 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODV_RETURN(_ret_ref)) |
dcubed@3202 | 2128 | DEFINE_CALLNONVIRTUALMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 2129 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2130 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODV_RETURN()) |
dcubed@3202 | 2131 | DEFINE_CALLNONVIRTUALMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2132 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2133 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODV_RETURN()) |
dcubed@3202 | 2134 | |
dcubed@3202 | 2135 | #define DEFINE_CALLNONVIRTUALMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 2136 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2137 | \ |
dcubed@3202 | 2138 | DT_RETURN_MARK_DECL_FOR(Result, CallNonvirtual##Result##MethodA, ResultType \ |
dcubed@3202 | 2139 | , ReturnProbe);\ |
dcubed@3202 | 2140 | \ |
dcubed@3202 | 2141 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2142 | jni_CallNonvirtual##Result##MethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 2143 | JNIWrapper("CallNonvitual" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 2144 | \ |
dcubed@3202 | 2145 | EntryProbe;\ |
dcubed@3202 | 2146 | ResultType ret;\ |
dcubed@3202 | 2147 | DT_RETURN_MARK_FOR(Result, CallNonvirtual##Result##MethodA, ResultType, \ |
dcubed@3202 | 2148 | (const ResultType&)ret);\ |
dcubed@3202 | 2149 | \ |
dcubed@3202 | 2150 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2151 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 2152 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2153 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2154 | return ret;\ |
dcubed@3202 | 2155 | JNI_END |
dcubed@3202 | 2156 | |
dcubed@3202 | 2157 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2158 | DEFINE_CALLNONVIRTUALMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2159 | , HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2160 | HOTSPOT_JNI_CALLNONVIRTUALBOOLEANMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2161 | DEFINE_CALLNONVIRTUALMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 2162 | , HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2163 | HOTSPOT_JNI_CALLNONVIRTUALBYTEMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2164 | DEFINE_CALLNONVIRTUALMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 2165 | , HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2166 | HOTSPOT_JNI_CALLNONVIRTUALCHARMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2167 | DEFINE_CALLNONVIRTUALMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 2168 | , HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2169 | HOTSPOT_JNI_CALLNONVIRTUALSHORTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2170 | |
dcubed@3202 | 2171 | DEFINE_CALLNONVIRTUALMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 2172 | , HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2173 | HOTSPOT_JNI_CALLNONVIRTUALOBJECTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2174 | DEFINE_CALLNONVIRTUALMETHODA(jint, Int, T_INT |
dcubed@3202 | 2175 | , HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2176 | HOTSPOT_JNI_CALLNONVIRTUALINTMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2177 | DEFINE_CALLNONVIRTUALMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 2178 | , HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2179 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2180 | HOTSPOT_JNI_CALLNONVIRTUALLONGMETHODA_RETURN(_ret_ref)) |
dcubed@3202 | 2181 | DEFINE_CALLNONVIRTUALMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 2182 | , HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2183 | HOTSPOT_JNI_CALLNONVIRTUALFLOATMETHODA_RETURN()) |
dcubed@3202 | 2184 | DEFINE_CALLNONVIRTUALMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2185 | , HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_ENTRY(env, obj, cls, (uintptr_t)methodID), |
dcubed@3202 | 2186 | HOTSPOT_JNI_CALLNONVIRTUALDOUBLEMETHODA_RETURN()) |
dcubed@3202 | 2187 | |
dcubed@3202 | 2188 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethod |
dcubed@3202 | 2189 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_RETURN()); |
dcubed@3202 | 2190 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodV |
dcubed@3202 | 2191 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_RETURN()); |
dcubed@3202 | 2192 | DT_VOID_RETURN_MARK_DECL(CallNonvirtualVoidMethodA |
dcubed@3202 | 2193 | , HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_RETURN()); |
dcubed@3202 | 2194 | #endif /* USDT2 */ |
dcubed@3202 | 2195 | |
duke@435 | 2196 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, ...)) |
duke@435 | 2197 | JNIWrapper("CallNonvirtualVoidMethod"); |
duke@435 | 2198 | |
dcubed@3202 | 2199 | #ifndef USDT2 |
duke@435 | 2200 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethod__entry, |
duke@435 | 2201 | env, obj, cls, methodID); |
dcubed@3202 | 2202 | #else /* USDT2 */ |
dcubed@3202 | 2203 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHOD_ENTRY( |
dcubed@3202 | 2204 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2205 | #endif /* USDT2 */ |
duke@435 | 2206 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethod); |
duke@435 | 2207 | |
duke@435 | 2208 | va_list args; |
duke@435 | 2209 | va_start(args, methodID); |
duke@435 | 2210 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2211 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2212 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2213 | va_end(args); |
duke@435 | 2214 | JNI_END |
duke@435 | 2215 | |
duke@435 | 2216 | |
duke@435 | 2217 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, va_list args)) |
duke@435 | 2218 | JNIWrapper("CallNonvirtualVoidMethodV"); |
duke@435 | 2219 | |
dcubed@3202 | 2220 | #ifndef USDT2 |
duke@435 | 2221 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodV__entry, |
duke@435 | 2222 | env, obj, cls, methodID); |
dcubed@3202 | 2223 | #else /* USDT2 */ |
dcubed@3202 | 2224 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODV_ENTRY( |
dcubed@3202 | 2225 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2226 | #endif /* USDT2 */ |
duke@435 | 2227 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodV); |
duke@435 | 2228 | |
duke@435 | 2229 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2230 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2231 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2232 | JNI_END |
duke@435 | 2233 | |
duke@435 | 2234 | |
duke@435 | 2235 | JNI_ENTRY(void, jni_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass cls, jmethodID methodID, const jvalue *args)) |
duke@435 | 2236 | JNIWrapper("CallNonvirtualVoidMethodA"); |
dcubed@3202 | 2237 | #ifndef USDT2 |
duke@435 | 2238 | DTRACE_PROBE4(hotspot_jni, CallNonvirtualVoidMethodA__entry, |
duke@435 | 2239 | env, obj, cls, methodID); |
dcubed@3202 | 2240 | #else /* USDT2 */ |
dcubed@3202 | 2241 | HOTSPOT_JNI_CALLNONVIRTUALVOIDMETHODA_ENTRY( |
dcubed@3202 | 2242 | env, obj, cls, (uintptr_t) methodID); |
dcubed@3202 | 2243 | #endif /* USDT2 */ |
duke@435 | 2244 | DT_VOID_RETURN_MARK(CallNonvirtualVoidMethodA); |
duke@435 | 2245 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2246 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 2247 | jni_invoke_nonstatic(env, &jvalue, obj, JNI_NONVIRTUAL, methodID, &ap, CHECK); |
duke@435 | 2248 | JNI_END |
duke@435 | 2249 | |
duke@435 | 2250 | |
dcubed@3202 | 2251 | #ifndef USDT2 |
duke@435 | 2252 | #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag) \ |
duke@435 | 2253 | \ |
duke@435 | 2254 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType);\ |
duke@435 | 2255 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType);\ |
duke@435 | 2256 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType);\ |
duke@435 | 2257 | \ |
duke@435 | 2258 | JNI_ENTRY(ResultType, \ |
duke@435 | 2259 | jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ |
duke@435 | 2260 | JNIWrapper("CallStatic" XSTR(Result) "Method"); \ |
duke@435 | 2261 | \ |
duke@435 | 2262 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##Method__entry, env, cls, methodID);\ |
duke@435 | 2263 | ResultType ret = 0;\ |
duke@435 | 2264 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ |
duke@435 | 2265 | (const ResultType&)ret);\ |
duke@435 | 2266 | \ |
duke@435 | 2267 | va_list args; \ |
duke@435 | 2268 | va_start(args, methodID); \ |
duke@435 | 2269 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2270 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 2271 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2272 | va_end(args); \ |
duke@435 | 2273 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2274 | return ret;\ |
duke@435 | 2275 | JNI_END \ |
duke@435 | 2276 | \ |
duke@435 | 2277 | JNI_ENTRY(ResultType, \ |
duke@435 | 2278 | jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ |
duke@435 | 2279 | JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ |
duke@435 | 2280 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodV__entry, env, cls, methodID);\ |
duke@435 | 2281 | ResultType ret = 0;\ |
duke@435 | 2282 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ |
duke@435 | 2283 | (const ResultType&)ret);\ |
duke@435 | 2284 | \ |
duke@435 | 2285 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2286 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
duke@435 | 2287 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2288 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2289 | return ret;\ |
duke@435 | 2290 | JNI_END \ |
duke@435 | 2291 | \ |
duke@435 | 2292 | JNI_ENTRY(ResultType, \ |
duke@435 | 2293 | jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ |
duke@435 | 2294 | JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ |
duke@435 | 2295 | DTRACE_PROBE3(hotspot_jni, CallStatic##Result##MethodA__entry, env, cls, methodID);\ |
duke@435 | 2296 | ResultType ret = 0;\ |
duke@435 | 2297 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ |
duke@435 | 2298 | (const ResultType&)ret);\ |
duke@435 | 2299 | \ |
duke@435 | 2300 | JavaValue jvalue(Tag); \ |
coleenp@2497 | 2301 | JNI_ArgumentPusherArray ap(methodID, args); \ |
duke@435 | 2302 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
duke@435 | 2303 | ret = jvalue.get_##ResultType(); \ |
duke@435 | 2304 | return ret;\ |
duke@435 | 2305 | JNI_END |
duke@435 | 2306 | |
duke@435 | 2307 | // the runtime type of subword integral basic types is integer |
duke@435 | 2308 | DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN) |
duke@435 | 2309 | DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE) |
duke@435 | 2310 | DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR) |
duke@435 | 2311 | DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT) |
duke@435 | 2312 | |
duke@435 | 2313 | DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT) |
duke@435 | 2314 | DEFINE_CALLSTATICMETHOD(jint, Int, T_INT) |
duke@435 | 2315 | DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG) |
duke@435 | 2316 | DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT) |
duke@435 | 2317 | DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE) |
duke@435 | 2318 | |
duke@435 | 2319 | |
duke@435 | 2320 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod); |
duke@435 | 2321 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV); |
duke@435 | 2322 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA); |
duke@435 | 2323 | |
dcubed@3202 | 2324 | #else /* USDT2 */ |
dcubed@3202 | 2325 | |
dcubed@3202 | 2326 | #define DEFINE_CALLSTATICMETHOD(ResultType, Result, Tag \ |
dcubed@3202 | 2327 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2328 | \ |
dcubed@3202 | 2329 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##Method, ResultType \ |
dcubed@3202 | 2330 | , ResultProbe); \ |
dcubed@3202 | 2331 | \ |
dcubed@3202 | 2332 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2333 | jni_CallStatic##Result##Method(JNIEnv *env, jclass cls, jmethodID methodID, ...)) \ |
dcubed@3202 | 2334 | JNIWrapper("CallStatic" XSTR(Result) "Method"); \ |
dcubed@3202 | 2335 | \ |
dcubed@3202 | 2336 | EntryProbe; \ |
dcubed@3202 | 2337 | ResultType ret = 0;\ |
dcubed@3202 | 2338 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##Method, ResultType, \ |
dcubed@3202 | 2339 | (const ResultType&)ret);\ |
dcubed@3202 | 2340 | \ |
dcubed@3202 | 2341 | va_list args; \ |
dcubed@3202 | 2342 | va_start(args, methodID); \ |
dcubed@3202 | 2343 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2344 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2345 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2346 | va_end(args); \ |
dcubed@3202 | 2347 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2348 | return ret;\ |
dcubed@3202 | 2349 | JNI_END |
dcubed@3202 | 2350 | |
dcubed@3202 | 2351 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2352 | DEFINE_CALLSTATICMETHOD(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2353 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2354 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2355 | DEFINE_CALLSTATICMETHOD(jbyte, Byte, T_BYTE |
dcubed@3202 | 2356 | , HOTSPOT_JNI_CALLSTATICBYTEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2357 | HOTSPOT_JNI_CALLSTATICBYTEMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2358 | DEFINE_CALLSTATICMETHOD(jchar, Char, T_CHAR |
dcubed@3202 | 2359 | , HOTSPOT_JNI_CALLSTATICCHARMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2360 | HOTSPOT_JNI_CALLSTATICCHARMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2361 | DEFINE_CALLSTATICMETHOD(jshort, Short, T_SHORT |
dcubed@3202 | 2362 | , HOTSPOT_JNI_CALLSTATICSHORTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2363 | HOTSPOT_JNI_CALLSTATICSHORTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2364 | |
dcubed@3202 | 2365 | DEFINE_CALLSTATICMETHOD(jobject, Object, T_OBJECT |
dcubed@3202 | 2366 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2367 | HOTSPOT_JNI_CALLSTATICOBJECTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2368 | DEFINE_CALLSTATICMETHOD(jint, Int, T_INT |
dcubed@3202 | 2369 | , HOTSPOT_JNI_CALLSTATICINTMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2370 | HOTSPOT_JNI_CALLSTATICINTMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2371 | DEFINE_CALLSTATICMETHOD(jlong, Long, T_LONG |
dcubed@3202 | 2372 | , HOTSPOT_JNI_CALLSTATICLONGMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2373 | HOTSPOT_JNI_CALLSTATICLONGMETHOD_RETURN(_ret_ref)); |
dcubed@3202 | 2374 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2375 | DEFINE_CALLSTATICMETHOD(jfloat, Float, T_FLOAT |
dcubed@3202 | 2376 | , HOTSPOT_JNI_CALLSTATICFLOATMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2377 | HOTSPOT_JNI_CALLSTATICFLOATMETHOD_RETURN()); |
dcubed@3202 | 2378 | DEFINE_CALLSTATICMETHOD(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2379 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2380 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHOD_RETURN()); |
dcubed@3202 | 2381 | |
dcubed@3202 | 2382 | #define DEFINE_CALLSTATICMETHODV(ResultType, Result, Tag \ |
dcubed@3202 | 2383 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2384 | \ |
dcubed@3202 | 2385 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodV, ResultType \ |
dcubed@3202 | 2386 | , ResultProbe); \ |
dcubed@3202 | 2387 | \ |
dcubed@3202 | 2388 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2389 | jni_CallStatic##Result##MethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) \ |
dcubed@3202 | 2390 | JNIWrapper("CallStatic" XSTR(Result) "MethodV"); \ |
dcubed@3202 | 2391 | \ |
dcubed@3202 | 2392 | EntryProbe; \ |
dcubed@3202 | 2393 | ResultType ret = 0;\ |
dcubed@3202 | 2394 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodV, ResultType, \ |
dcubed@3202 | 2395 | (const ResultType&)ret);\ |
dcubed@3202 | 2396 | \ |
dcubed@3202 | 2397 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2398 | JNI_ArgumentPusherVaArg ap(methodID, args); \ |
dcubed@3202 | 2399 | /* Make sure class is initialized before trying to invoke its method */ \ |
coleenp@4037 | 2400 | KlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls))); \ |
hseigel@4278 | 2401 | k()->initialize(CHECK_0); \ |
dcubed@3202 | 2402 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2403 | va_end(args); \ |
dcubed@3202 | 2404 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2405 | return ret;\ |
dcubed@3202 | 2406 | JNI_END |
dcubed@3202 | 2407 | |
dcubed@3202 | 2408 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2409 | DEFINE_CALLSTATICMETHODV(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2410 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2411 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2412 | DEFINE_CALLSTATICMETHODV(jbyte, Byte, T_BYTE |
dcubed@3202 | 2413 | , HOTSPOT_JNI_CALLSTATICBYTEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2414 | HOTSPOT_JNI_CALLSTATICBYTEMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2415 | DEFINE_CALLSTATICMETHODV(jchar, Char, T_CHAR |
dcubed@3202 | 2416 | , HOTSPOT_JNI_CALLSTATICCHARMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2417 | HOTSPOT_JNI_CALLSTATICCHARMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2418 | DEFINE_CALLSTATICMETHODV(jshort, Short, T_SHORT |
dcubed@3202 | 2419 | , HOTSPOT_JNI_CALLSTATICSHORTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2420 | HOTSPOT_JNI_CALLSTATICSHORTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2421 | |
dcubed@3202 | 2422 | DEFINE_CALLSTATICMETHODV(jobject, Object, T_OBJECT |
dcubed@3202 | 2423 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2424 | HOTSPOT_JNI_CALLSTATICOBJECTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2425 | DEFINE_CALLSTATICMETHODV(jint, Int, T_INT |
dcubed@3202 | 2426 | , HOTSPOT_JNI_CALLSTATICINTMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2427 | HOTSPOT_JNI_CALLSTATICINTMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2428 | DEFINE_CALLSTATICMETHODV(jlong, Long, T_LONG |
dcubed@3202 | 2429 | , HOTSPOT_JNI_CALLSTATICLONGMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2430 | HOTSPOT_JNI_CALLSTATICLONGMETHODV_RETURN(_ret_ref)); |
dcubed@3202 | 2431 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2432 | DEFINE_CALLSTATICMETHODV(jfloat, Float, T_FLOAT |
dcubed@3202 | 2433 | , HOTSPOT_JNI_CALLSTATICFLOATMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2434 | HOTSPOT_JNI_CALLSTATICFLOATMETHODV_RETURN()); |
dcubed@3202 | 2435 | DEFINE_CALLSTATICMETHODV(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2436 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2437 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHODV_RETURN()); |
dcubed@3202 | 2438 | |
dcubed@3202 | 2439 | #define DEFINE_CALLSTATICMETHODA(ResultType, Result, Tag \ |
dcubed@3202 | 2440 | , EntryProbe, ResultProbe) \ |
dcubed@3202 | 2441 | \ |
dcubed@3202 | 2442 | DT_RETURN_MARK_DECL_FOR(Result, CallStatic##Result##MethodA, ResultType \ |
dcubed@3202 | 2443 | , ResultProbe); \ |
dcubed@3202 | 2444 | \ |
dcubed@3202 | 2445 | JNI_ENTRY(ResultType, \ |
dcubed@3202 | 2446 | jni_CallStatic##Result##MethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) \ |
dcubed@3202 | 2447 | JNIWrapper("CallStatic" XSTR(Result) "MethodA"); \ |
dcubed@3202 | 2448 | \ |
dcubed@3202 | 2449 | EntryProbe; \ |
dcubed@3202 | 2450 | ResultType ret = 0;\ |
dcubed@3202 | 2451 | DT_RETURN_MARK_FOR(Result, CallStatic##Result##MethodA, ResultType, \ |
dcubed@3202 | 2452 | (const ResultType&)ret);\ |
dcubed@3202 | 2453 | \ |
dcubed@3202 | 2454 | JavaValue jvalue(Tag); \ |
dcubed@3202 | 2455 | JNI_ArgumentPusherArray ap(methodID, args); \ |
dcubed@3202 | 2456 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK_0); \ |
dcubed@3202 | 2457 | ret = jvalue.get_##ResultType(); \ |
dcubed@3202 | 2458 | return ret;\ |
dcubed@3202 | 2459 | JNI_END |
dcubed@3202 | 2460 | |
dcubed@3202 | 2461 | // the runtime type of subword integral basic types is integer |
dcubed@3202 | 2462 | DEFINE_CALLSTATICMETHODA(jboolean, Boolean, T_BOOLEAN |
dcubed@3202 | 2463 | , HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2464 | HOTSPOT_JNI_CALLSTATICBOOLEANMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2465 | DEFINE_CALLSTATICMETHODA(jbyte, Byte, T_BYTE |
dcubed@3202 | 2466 | , HOTSPOT_JNI_CALLSTATICBYTEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2467 | HOTSPOT_JNI_CALLSTATICBYTEMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2468 | DEFINE_CALLSTATICMETHODA(jchar, Char, T_CHAR |
dcubed@3202 | 2469 | , HOTSPOT_JNI_CALLSTATICCHARMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2470 | HOTSPOT_JNI_CALLSTATICCHARMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2471 | DEFINE_CALLSTATICMETHODA(jshort, Short, T_SHORT |
dcubed@3202 | 2472 | , HOTSPOT_JNI_CALLSTATICSHORTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2473 | HOTSPOT_JNI_CALLSTATICSHORTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2474 | |
dcubed@3202 | 2475 | DEFINE_CALLSTATICMETHODA(jobject, Object, T_OBJECT |
dcubed@3202 | 2476 | , HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2477 | HOTSPOT_JNI_CALLSTATICOBJECTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2478 | DEFINE_CALLSTATICMETHODA(jint, Int, T_INT |
dcubed@3202 | 2479 | , HOTSPOT_JNI_CALLSTATICINTMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2480 | HOTSPOT_JNI_CALLSTATICINTMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2481 | DEFINE_CALLSTATICMETHODA(jlong, Long, T_LONG |
dcubed@3202 | 2482 | , HOTSPOT_JNI_CALLSTATICLONGMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2483 | HOTSPOT_JNI_CALLSTATICLONGMETHODA_RETURN(_ret_ref)); |
dcubed@3202 | 2484 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2485 | DEFINE_CALLSTATICMETHODA(jfloat, Float, T_FLOAT |
dcubed@3202 | 2486 | , HOTSPOT_JNI_CALLSTATICFLOATMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2487 | HOTSPOT_JNI_CALLSTATICFLOATMETHODA_RETURN()); |
dcubed@3202 | 2488 | DEFINE_CALLSTATICMETHODA(jdouble, Double, T_DOUBLE |
dcubed@3202 | 2489 | , HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_ENTRY(env, cls, (uintptr_t)methodID), |
dcubed@3202 | 2490 | HOTSPOT_JNI_CALLSTATICDOUBLEMETHODA_RETURN()); |
dcubed@3202 | 2491 | |
dcubed@3202 | 2492 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethod |
dcubed@3202 | 2493 | , HOTSPOT_JNI_CALLSTATICVOIDMETHOD_RETURN()); |
dcubed@3202 | 2494 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodV |
dcubed@3202 | 2495 | , HOTSPOT_JNI_CALLSTATICVOIDMETHODV_RETURN()); |
dcubed@3202 | 2496 | DT_VOID_RETURN_MARK_DECL(CallStaticVoidMethodA |
dcubed@3202 | 2497 | , HOTSPOT_JNI_CALLSTATICVOIDMETHODA_RETURN()); |
dcubed@3202 | 2498 | #endif /* USDT2 */ |
dcubed@3202 | 2499 | |
duke@435 | 2500 | JNI_ENTRY(void, jni_CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)) |
duke@435 | 2501 | JNIWrapper("CallStaticVoidMethod"); |
dcubed@3202 | 2502 | #ifndef USDT2 |
duke@435 | 2503 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethod__entry, env, cls, methodID); |
dcubed@3202 | 2504 | #else /* USDT2 */ |
dcubed@3202 | 2505 | HOTSPOT_JNI_CALLSTATICVOIDMETHOD_ENTRY( |
dcubed@3202 | 2506 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2507 | #endif /* USDT2 */ |
duke@435 | 2508 | DT_VOID_RETURN_MARK(CallStaticVoidMethod); |
duke@435 | 2509 | |
duke@435 | 2510 | va_list args; |
duke@435 | 2511 | va_start(args, methodID); |
duke@435 | 2512 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2513 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2514 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2515 | va_end(args); |
duke@435 | 2516 | JNI_END |
duke@435 | 2517 | |
duke@435 | 2518 | |
duke@435 | 2519 | JNI_ENTRY(void, jni_CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)) |
duke@435 | 2520 | JNIWrapper("CallStaticVoidMethodV"); |
dcubed@3202 | 2521 | #ifndef USDT2 |
duke@435 | 2522 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodV__entry, env, cls, methodID); |
dcubed@3202 | 2523 | #else /* USDT2 */ |
dcubed@3202 | 2524 | HOTSPOT_JNI_CALLSTATICVOIDMETHODV_ENTRY( |
dcubed@3202 | 2525 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2526 | #endif /* USDT2 */ |
duke@435 | 2527 | DT_VOID_RETURN_MARK(CallStaticVoidMethodV); |
duke@435 | 2528 | |
duke@435 | 2529 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2530 | JNI_ArgumentPusherVaArg ap(methodID, args); |
duke@435 | 2531 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2532 | JNI_END |
duke@435 | 2533 | |
duke@435 | 2534 | |
duke@435 | 2535 | JNI_ENTRY(void, jni_CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, const jvalue *args)) |
duke@435 | 2536 | JNIWrapper("CallStaticVoidMethodA"); |
dcubed@3202 | 2537 | #ifndef USDT2 |
duke@435 | 2538 | DTRACE_PROBE3(hotspot_jni, CallStaticVoidMethodA__entry, env, cls, methodID); |
dcubed@3202 | 2539 | #else /* USDT2 */ |
dcubed@3202 | 2540 | HOTSPOT_JNI_CALLSTATICVOIDMETHODA_ENTRY( |
dcubed@3202 | 2541 | env, cls, (uintptr_t) methodID); |
dcubed@3202 | 2542 | #endif /* USDT2 */ |
duke@435 | 2543 | DT_VOID_RETURN_MARK(CallStaticVoidMethodA); |
duke@435 | 2544 | |
duke@435 | 2545 | JavaValue jvalue(T_VOID); |
coleenp@2497 | 2546 | JNI_ArgumentPusherArray ap(methodID, args); |
duke@435 | 2547 | jni_invoke_static(env, &jvalue, NULL, JNI_STATIC, methodID, &ap, CHECK); |
duke@435 | 2548 | JNI_END |
duke@435 | 2549 | |
duke@435 | 2550 | |
duke@435 | 2551 | // |
duke@435 | 2552 | // Accessing Fields |
duke@435 | 2553 | // |
duke@435 | 2554 | |
duke@435 | 2555 | |
dcubed@3202 | 2556 | #ifndef USDT2 |
duke@435 | 2557 | DT_RETURN_MARK_DECL(GetFieldID, jfieldID); |
dcubed@3202 | 2558 | #else /* USDT2 */ |
dcubed@3202 | 2559 | DT_RETURN_MARK_DECL(GetFieldID, jfieldID |
dcubed@3202 | 2560 | , HOTSPOT_JNI_GETFIELDID_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 2561 | #endif /* USDT2 */ |
duke@435 | 2562 | |
duke@435 | 2563 | JNI_ENTRY(jfieldID, jni_GetFieldID(JNIEnv *env, jclass clazz, |
duke@435 | 2564 | const char *name, const char *sig)) |
duke@435 | 2565 | JNIWrapper("GetFieldID"); |
dcubed@3202 | 2566 | #ifndef USDT2 |
duke@435 | 2567 | DTRACE_PROBE4(hotspot_jni, GetFieldID__entry, env, clazz, name, sig); |
dcubed@3202 | 2568 | #else /* USDT2 */ |
dcubed@3202 | 2569 | HOTSPOT_JNI_GETFIELDID_ENTRY( |
dcubed@3202 | 2570 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 2571 | #endif /* USDT2 */ |
duke@435 | 2572 | jfieldID ret = 0; |
duke@435 | 2573 | DT_RETURN_MARK(GetFieldID, jfieldID, (const jfieldID&)ret); |
duke@435 | 2574 | |
duke@435 | 2575 | // The class should have been loaded (we have an instance of the class |
duke@435 | 2576 | // passed in) so the field and signature should already be in the symbol |
duke@435 | 2577 | // table. If they're not there, the field doesn't exist. |
coleenp@2497 | 2578 | TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
coleenp@2497 | 2579 | TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 2580 | if (fieldname == NULL || signame == NULL) { |
duke@435 | 2581 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2582 | } |
duke@435 | 2583 | KlassHandle k(THREAD, |
coleenp@4037 | 2584 | java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 2585 | // Make sure class is initialized before handing id's out to fields |
hseigel@4278 | 2586 | k()->initialize(CHECK_NULL); |
duke@435 | 2587 | |
duke@435 | 2588 | fieldDescriptor fd; |
hseigel@4278 | 2589 | if (!k()->oop_is_instance() || |
coleenp@4037 | 2590 | !InstanceKlass::cast(k())->find_field(fieldname, signame, false, &fd)) { |
duke@435 | 2591 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2592 | } |
duke@435 | 2593 | |
duke@435 | 2594 | // A jfieldID for a non-static field is simply the offset of the field within the instanceOop |
duke@435 | 2595 | // It may also have hash bits for k, if VerifyJNIFields is turned on. |
duke@435 | 2596 | ret = jfieldIDWorkaround::to_instance_jfieldID(k(), fd.offset()); |
duke@435 | 2597 | return ret; |
duke@435 | 2598 | JNI_END |
duke@435 | 2599 | |
duke@435 | 2600 | |
duke@435 | 2601 | JNI_ENTRY(jobject, jni_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)) |
duke@435 | 2602 | JNIWrapper("GetObjectField"); |
dcubed@3202 | 2603 | #ifndef USDT2 |
duke@435 | 2604 | DTRACE_PROBE3(hotspot_jni, GetObjectField__entry, env, obj, fieldID); |
dcubed@3202 | 2605 | #else /* USDT2 */ |
dcubed@3202 | 2606 | HOTSPOT_JNI_GETOBJECTFIELD_ENTRY( |
dcubed@3202 | 2607 | env, obj, (uintptr_t) fieldID); |
dcubed@3202 | 2608 | #endif /* USDT2 */ |
duke@435 | 2609 | oop o = JNIHandles::resolve_non_null(obj); |
coleenp@4037 | 2610 | Klass* k = o->klass(); |
duke@435 | 2611 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
duke@435 | 2612 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 2613 | // jni_GetField_probe() assumes that is okay to create handles. |
duke@435 | 2614 | if (JvmtiExport::should_post_field_access()) { |
duke@435 | 2615 | o = JvmtiExport::jni_GetField_probe(thread, obj, o, k, fieldID, false); |
duke@435 | 2616 | } |
duke@435 | 2617 | jobject ret = JNIHandles::make_local(env, o->obj_field(offset)); |
jprovino@4542 | 2618 | #if INCLUDE_ALL_GCS |
johnc@2781 | 2619 | // If G1 is enabled and we are accessing the value of the referent |
johnc@2781 | 2620 | // field in a reference object then we need to register a non-null |
johnc@2781 | 2621 | // referent with the SATB barrier. |
johnc@2781 | 2622 | if (UseG1GC) { |
johnc@2781 | 2623 | bool needs_barrier = false; |
johnc@2781 | 2624 | |
johnc@2781 | 2625 | if (ret != NULL && |
johnc@2781 | 2626 | offset == java_lang_ref_Reference::referent_offset && |
coleenp@4037 | 2627 | InstanceKlass::cast(k)->reference_type() != REF_NONE) { |
coleenp@4037 | 2628 | assert(InstanceKlass::cast(k)->is_subclass_of(SystemDictionary::Reference_klass()), "sanity"); |
johnc@2781 | 2629 | needs_barrier = true; |
johnc@2781 | 2630 | } |
johnc@2781 | 2631 | |
johnc@2781 | 2632 | if (needs_barrier) { |
johnc@2781 | 2633 | oop referent = JNIHandles::resolve(ret); |
johnc@2781 | 2634 | G1SATBCardTableModRefBS::enqueue(referent); |
johnc@2781 | 2635 | } |
johnc@2781 | 2636 | } |
jprovino@4542 | 2637 | #endif // INCLUDE_ALL_GCS |
dcubed@3202 | 2638 | #ifndef USDT2 |
duke@435 | 2639 | DTRACE_PROBE1(hotspot_jni, GetObjectField__return, ret); |
dcubed@3202 | 2640 | #else /* USDT2 */ |
dcubed@3202 | 2641 | HOTSPOT_JNI_GETOBJECTFIELD_RETURN( |
dcubed@3202 | 2642 | ret); |
dcubed@3202 | 2643 | #endif /* USDT2 */ |
duke@435 | 2644 | return ret; |
duke@435 | 2645 | JNI_END |
duke@435 | 2646 | |
duke@435 | 2647 | |
dcubed@3202 | 2648 | #ifndef USDT2 |
duke@435 | 2649 | #define DEFINE_GETFIELD(Return,Fieldname,Result) \ |
duke@435 | 2650 | \ |
duke@435 | 2651 | DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return);\ |
duke@435 | 2652 | \ |
duke@435 | 2653 | JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ |
duke@435 | 2654 | JNIWrapper("Get" XSTR(Result) "Field"); \ |
duke@435 | 2655 | \ |
duke@435 | 2656 | DTRACE_PROBE3(hotspot_jni, Get##Result##Field__entry, env, obj, fieldID);\ |
duke@435 | 2657 | Return ret = 0;\ |
duke@435 | 2658 | DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ |
duke@435 | 2659 | \ |
duke@435 | 2660 | oop o = JNIHandles::resolve_non_null(obj); \ |
coleenp@4037 | 2661 | Klass* k = o->klass(); \ |
duke@435 | 2662 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
duke@435 | 2663 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 2664 | /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ |
duke@435 | 2665 | /* and creates a ResetNoHandleMark. */ \ |
duke@435 | 2666 | if (JvmtiExport::should_post_field_access()) { \ |
duke@435 | 2667 | o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ |
duke@435 | 2668 | } \ |
duke@435 | 2669 | ret = o->Fieldname##_field(offset); \ |
duke@435 | 2670 | return ret; \ |
duke@435 | 2671 | JNI_END |
duke@435 | 2672 | |
duke@435 | 2673 | DEFINE_GETFIELD(jboolean, bool, Boolean) |
duke@435 | 2674 | DEFINE_GETFIELD(jbyte, byte, Byte) |
duke@435 | 2675 | DEFINE_GETFIELD(jchar, char, Char) |
duke@435 | 2676 | DEFINE_GETFIELD(jshort, short, Short) |
duke@435 | 2677 | DEFINE_GETFIELD(jint, int, Int) |
duke@435 | 2678 | DEFINE_GETFIELD(jlong, long, Long) |
duke@435 | 2679 | DEFINE_GETFIELD(jfloat, float, Float) |
duke@435 | 2680 | DEFINE_GETFIELD(jdouble, double, Double) |
duke@435 | 2681 | |
dcubed@3202 | 2682 | #else /* USDT2 */ |
dcubed@3202 | 2683 | |
dcubed@3202 | 2684 | #define DEFINE_GETFIELD(Return,Fieldname,Result \ |
dcubed@3202 | 2685 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2686 | \ |
dcubed@3202 | 2687 | DT_RETURN_MARK_DECL_FOR(Result, Get##Result##Field, Return \ |
dcubed@3202 | 2688 | , ReturnProbe); \ |
dcubed@3202 | 2689 | \ |
dcubed@3202 | 2690 | JNI_QUICK_ENTRY(Return, jni_Get##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID)) \ |
dcubed@3202 | 2691 | JNIWrapper("Get" XSTR(Result) "Field"); \ |
dcubed@3202 | 2692 | \ |
dcubed@3202 | 2693 | EntryProbe; \ |
dcubed@3202 | 2694 | Return ret = 0;\ |
dcubed@3202 | 2695 | DT_RETURN_MARK_FOR(Result, Get##Result##Field, Return, (const Return&)ret);\ |
dcubed@3202 | 2696 | \ |
dcubed@3202 | 2697 | oop o = JNIHandles::resolve_non_null(obj); \ |
coleenp@4037 | 2698 | Klass* k = o->klass(); \ |
dcubed@3202 | 2699 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
dcubed@3202 | 2700 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 2701 | /* jni_GetField_probe_nh() assumes that is not okay to create handles */ \ |
dcubed@3202 | 2702 | /* and creates a ResetNoHandleMark. */ \ |
dcubed@3202 | 2703 | if (JvmtiExport::should_post_field_access()) { \ |
dcubed@3202 | 2704 | o = JvmtiExport::jni_GetField_probe_nh(thread, obj, o, k, fieldID, false); \ |
dcubed@3202 | 2705 | } \ |
dcubed@3202 | 2706 | ret = o->Fieldname##_field(offset); \ |
dcubed@3202 | 2707 | return ret; \ |
dcubed@3202 | 2708 | JNI_END |
dcubed@3202 | 2709 | |
dcubed@3202 | 2710 | DEFINE_GETFIELD(jboolean, bool, Boolean |
dcubed@3202 | 2711 | , HOTSPOT_JNI_GETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2712 | HOTSPOT_JNI_GETBOOLEANFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2713 | DEFINE_GETFIELD(jbyte, byte, Byte |
dcubed@3202 | 2714 | , HOTSPOT_JNI_GETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2715 | HOTSPOT_JNI_GETBYTEFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2716 | DEFINE_GETFIELD(jchar, char, Char |
dcubed@3202 | 2717 | , HOTSPOT_JNI_GETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2718 | HOTSPOT_JNI_GETCHARFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2719 | DEFINE_GETFIELD(jshort, short, Short |
dcubed@3202 | 2720 | , HOTSPOT_JNI_GETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2721 | HOTSPOT_JNI_GETSHORTFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2722 | DEFINE_GETFIELD(jint, int, Int |
dcubed@3202 | 2723 | , HOTSPOT_JNI_GETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2724 | HOTSPOT_JNI_GETINTFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2725 | DEFINE_GETFIELD(jlong, long, Long |
dcubed@3202 | 2726 | , HOTSPOT_JNI_GETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2727 | HOTSPOT_JNI_GETLONGFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 2728 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2729 | DEFINE_GETFIELD(jfloat, float, Float |
dcubed@3202 | 2730 | , HOTSPOT_JNI_GETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2731 | HOTSPOT_JNI_GETFLOATFIELD_RETURN()) |
dcubed@3202 | 2732 | DEFINE_GETFIELD(jdouble, double, Double |
dcubed@3202 | 2733 | , HOTSPOT_JNI_GETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2734 | HOTSPOT_JNI_GETDOUBLEFIELD_RETURN()) |
dcubed@3202 | 2735 | #endif /* USDT2 */ |
dcubed@3202 | 2736 | |
duke@435 | 2737 | address jni_GetBooleanField_addr() { |
duke@435 | 2738 | return (address)jni_GetBooleanField; |
duke@435 | 2739 | } |
duke@435 | 2740 | address jni_GetByteField_addr() { |
duke@435 | 2741 | return (address)jni_GetByteField; |
duke@435 | 2742 | } |
duke@435 | 2743 | address jni_GetCharField_addr() { |
duke@435 | 2744 | return (address)jni_GetCharField; |
duke@435 | 2745 | } |
duke@435 | 2746 | address jni_GetShortField_addr() { |
duke@435 | 2747 | return (address)jni_GetShortField; |
duke@435 | 2748 | } |
duke@435 | 2749 | address jni_GetIntField_addr() { |
duke@435 | 2750 | return (address)jni_GetIntField; |
duke@435 | 2751 | } |
duke@435 | 2752 | address jni_GetLongField_addr() { |
duke@435 | 2753 | return (address)jni_GetLongField; |
duke@435 | 2754 | } |
duke@435 | 2755 | address jni_GetFloatField_addr() { |
duke@435 | 2756 | return (address)jni_GetFloatField; |
duke@435 | 2757 | } |
duke@435 | 2758 | address jni_GetDoubleField_addr() { |
duke@435 | 2759 | return (address)jni_GetDoubleField; |
duke@435 | 2760 | } |
duke@435 | 2761 | |
duke@435 | 2762 | JNI_QUICK_ENTRY(void, jni_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)) |
duke@435 | 2763 | JNIWrapper("SetObjectField"); |
dcubed@3202 | 2764 | #ifndef USDT2 |
duke@435 | 2765 | DTRACE_PROBE4(hotspot_jni, SetObjectField__entry, env, obj, fieldID, value); |
dcubed@3202 | 2766 | #else /* USDT2 */ |
dcubed@3202 | 2767 | HOTSPOT_JNI_SETOBJECTFIELD_ENTRY( |
dcubed@3202 | 2768 | env, obj, (uintptr_t) fieldID, value); |
dcubed@3202 | 2769 | #endif /* USDT2 */ |
duke@435 | 2770 | oop o = JNIHandles::resolve_non_null(obj); |
coleenp@4037 | 2771 | Klass* k = o->klass(); |
duke@435 | 2772 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
duke@435 | 2773 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 2774 | // jni_SetField_probe_nh() assumes that is not okay to create handles |
duke@435 | 2775 | // and creates a ResetNoHandleMark. |
duke@435 | 2776 | if (JvmtiExport::should_post_field_modification()) { |
duke@435 | 2777 | jvalue field_value; |
duke@435 | 2778 | field_value.l = value; |
duke@435 | 2779 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, 'L', (jvalue *)&field_value); |
duke@435 | 2780 | } |
duke@435 | 2781 | o->obj_field_put(offset, JNIHandles::resolve(value)); |
dcubed@3202 | 2782 | #ifndef USDT2 |
duke@435 | 2783 | DTRACE_PROBE(hotspot_jni, SetObjectField__return); |
dcubed@3202 | 2784 | #else /* USDT2 */ |
dcubed@3202 | 2785 | HOTSPOT_JNI_SETOBJECTFIELD_RETURN( |
dcubed@3202 | 2786 | ); |
dcubed@3202 | 2787 | #endif /* USDT2 */ |
duke@435 | 2788 | JNI_END |
duke@435 | 2789 | |
dcubed@3202 | 2790 | #ifndef USDT2 |
duke@435 | 2791 | #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
duke@435 | 2792 | \ |
duke@435 | 2793 | JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ |
duke@435 | 2794 | JNIWrapper("Set" XSTR(Result) "Field"); \ |
duke@435 | 2795 | \ |
coleenp@4148 | 2796 | FP_SELECT_##Result( \ |
coleenp@4148 | 2797 | DTRACE_PROBE4(hotspot_jni, Set##Result##Field__entry, env, obj, fieldID, value), \ |
coleenp@4148 | 2798 | DTRACE_PROBE3(hotspot_jni, Set##Result##Field__entry, env, obj, fieldID)); \ |
duke@435 | 2799 | \ |
duke@435 | 2800 | oop o = JNIHandles::resolve_non_null(obj); \ |
coleenp@4037 | 2801 | Klass* k = o->klass(); \ |
duke@435 | 2802 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
duke@435 | 2803 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 2804 | /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ |
duke@435 | 2805 | /* and creates a ResetNoHandleMark. */ \ |
duke@435 | 2806 | if (JvmtiExport::should_post_field_modification()) { \ |
duke@435 | 2807 | jvalue field_value; \ |
duke@435 | 2808 | field_value.unionType = value; \ |
duke@435 | 2809 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ |
duke@435 | 2810 | } \ |
duke@435 | 2811 | o->Fieldname##_field_put(offset, value); \ |
duke@435 | 2812 | DTRACE_PROBE(hotspot_jni, Set##Result##Field__return);\ |
duke@435 | 2813 | JNI_END |
duke@435 | 2814 | |
duke@435 | 2815 | DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z) |
duke@435 | 2816 | DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b) |
duke@435 | 2817 | DEFINE_SETFIELD(jchar, char, Char, 'C', c) |
duke@435 | 2818 | DEFINE_SETFIELD(jshort, short, Short, 'S', s) |
duke@435 | 2819 | DEFINE_SETFIELD(jint, int, Int, 'I', i) |
duke@435 | 2820 | DEFINE_SETFIELD(jlong, long, Long, 'J', j) |
duke@435 | 2821 | DEFINE_SETFIELD(jfloat, float, Float, 'F', f) |
duke@435 | 2822 | DEFINE_SETFIELD(jdouble, double, Double, 'D', d) |
duke@435 | 2823 | |
dcubed@3202 | 2824 | #else /* USDT2 */ |
dcubed@3202 | 2825 | |
dcubed@3202 | 2826 | #define DEFINE_SETFIELD(Argument,Fieldname,Result,SigType,unionType \ |
dcubed@3202 | 2827 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 2828 | \ |
dcubed@3202 | 2829 | JNI_QUICK_ENTRY(void, jni_Set##Result##Field(JNIEnv *env, jobject obj, jfieldID fieldID, Argument value)) \ |
dcubed@3202 | 2830 | JNIWrapper("Set" XSTR(Result) "Field"); \ |
dcubed@3202 | 2831 | \ |
dcubed@3202 | 2832 | EntryProbe; \ |
dcubed@3202 | 2833 | \ |
dcubed@3202 | 2834 | oop o = JNIHandles::resolve_non_null(obj); \ |
coleenp@4037 | 2835 | Klass* k = o->klass(); \ |
dcubed@3202 | 2836 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); \ |
dcubed@3202 | 2837 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 2838 | /* jni_SetField_probe_nh() assumes that is not okay to create handles */ \ |
dcubed@3202 | 2839 | /* and creates a ResetNoHandleMark. */ \ |
dcubed@3202 | 2840 | if (JvmtiExport::should_post_field_modification()) { \ |
dcubed@3202 | 2841 | jvalue field_value; \ |
dcubed@3202 | 2842 | field_value.unionType = value; \ |
dcubed@3202 | 2843 | o = JvmtiExport::jni_SetField_probe_nh(thread, obj, o, k, fieldID, false, SigType, (jvalue *)&field_value); \ |
dcubed@3202 | 2844 | } \ |
dcubed@3202 | 2845 | o->Fieldname##_field_put(offset, value); \ |
dcubed@3202 | 2846 | ReturnProbe; \ |
dcubed@3202 | 2847 | JNI_END |
dcubed@3202 | 2848 | |
dcubed@3202 | 2849 | DEFINE_SETFIELD(jboolean, bool, Boolean, 'Z', z |
dcubed@3202 | 2850 | , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2851 | HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) |
dcubed@3202 | 2852 | DEFINE_SETFIELD(jbyte, byte, Byte, 'B', b |
dcubed@3202 | 2853 | , HOTSPOT_JNI_SETBYTEFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2854 | HOTSPOT_JNI_SETBYTEFIELD_RETURN()) |
dcubed@3202 | 2855 | DEFINE_SETFIELD(jchar, char, Char, 'C', c |
dcubed@3202 | 2856 | , HOTSPOT_JNI_SETCHARFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2857 | HOTSPOT_JNI_SETCHARFIELD_RETURN()) |
dcubed@3202 | 2858 | DEFINE_SETFIELD(jshort, short, Short, 'S', s |
dcubed@3202 | 2859 | , HOTSPOT_JNI_SETSHORTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2860 | HOTSPOT_JNI_SETSHORTFIELD_RETURN()) |
dcubed@3202 | 2861 | DEFINE_SETFIELD(jint, int, Int, 'I', i |
dcubed@3202 | 2862 | , HOTSPOT_JNI_SETINTFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2863 | HOTSPOT_JNI_SETINTFIELD_RETURN()) |
dcubed@3202 | 2864 | DEFINE_SETFIELD(jlong, long, Long, 'J', j |
dcubed@3202 | 2865 | , HOTSPOT_JNI_SETLONGFIELD_ENTRY(env, obj, (uintptr_t)fieldID, value), |
dcubed@3202 | 2866 | HOTSPOT_JNI_SETLONGFIELD_RETURN()) |
dcubed@3202 | 2867 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 2868 | DEFINE_SETFIELD(jfloat, float, Float, 'F', f |
dcubed@3202 | 2869 | , HOTSPOT_JNI_SETFLOATFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2870 | HOTSPOT_JNI_SETFLOATFIELD_RETURN()) |
dcubed@3202 | 2871 | DEFINE_SETFIELD(jdouble, double, Double, 'D', d |
dcubed@3202 | 2872 | , HOTSPOT_JNI_SETDOUBLEFIELD_ENTRY(env, obj, (uintptr_t)fieldID), |
dcubed@3202 | 2873 | HOTSPOT_JNI_SETDOUBLEFIELD_RETURN()) |
dcubed@3202 | 2874 | #endif /* USDT2 */ |
dcubed@3202 | 2875 | |
dcubed@3202 | 2876 | #ifndef USDT2 |
duke@435 | 2877 | DT_RETURN_MARK_DECL(ToReflectedField, jobject); |
dcubed@3202 | 2878 | #else /* USDT2 */ |
dcubed@3202 | 2879 | DT_RETURN_MARK_DECL(ToReflectedField, jobject |
dcubed@3202 | 2880 | , HOTSPOT_JNI_TOREFLECTEDFIELD_RETURN(_ret_ref)); |
dcubed@3202 | 2881 | #endif /* USDT2 */ |
duke@435 | 2882 | |
duke@435 | 2883 | JNI_ENTRY(jobject, jni_ToReflectedField(JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic)) |
duke@435 | 2884 | JNIWrapper("ToReflectedField"); |
dcubed@3202 | 2885 | #ifndef USDT2 |
duke@435 | 2886 | DTRACE_PROBE4(hotspot_jni, ToReflectedField__entry, |
duke@435 | 2887 | env, cls, fieldID, isStatic); |
dcubed@3202 | 2888 | #else /* USDT2 */ |
dcubed@3202 | 2889 | HOTSPOT_JNI_TOREFLECTEDFIELD_ENTRY( |
dcubed@3202 | 2890 | env, cls, (uintptr_t) fieldID, isStatic); |
dcubed@3202 | 2891 | #endif /* USDT2 */ |
duke@435 | 2892 | jobject ret = NULL; |
duke@435 | 2893 | DT_RETURN_MARK(ToReflectedField, jobject, (const jobject&)ret); |
duke@435 | 2894 | |
duke@435 | 2895 | fieldDescriptor fd; |
duke@435 | 2896 | bool found = false; |
coleenp@4037 | 2897 | Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)); |
duke@435 | 2898 | |
duke@435 | 2899 | assert(jfieldIDWorkaround::is_static_jfieldID(fieldID) == (isStatic != 0), "invalid fieldID"); |
duke@435 | 2900 | |
duke@435 | 2901 | if (isStatic) { |
coleenp@4037 | 2902 | // Static field. The fieldID a JNIid specifying the field holder and the offset within the Klass*. |
duke@435 | 2903 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 2904 | assert(id->is_static_field_id(), "invalid static field id"); |
never@2658 | 2905 | found = id->find_local_field(&fd); |
duke@435 | 2906 | } else { |
duke@435 | 2907 | // Non-static field. The fieldID is really the offset of the field within the instanceOop. |
duke@435 | 2908 | int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); |
coleenp@4037 | 2909 | found = InstanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); |
duke@435 | 2910 | } |
duke@435 | 2911 | assert(found, "bad fieldID passed into jni_ToReflectedField"); |
duke@435 | 2912 | oop reflected = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); |
duke@435 | 2913 | ret = JNIHandles::make_local(env, reflected); |
duke@435 | 2914 | return ret; |
duke@435 | 2915 | JNI_END |
duke@435 | 2916 | |
duke@435 | 2917 | |
duke@435 | 2918 | // |
duke@435 | 2919 | // Accessing Static Fields |
duke@435 | 2920 | // |
dcubed@3202 | 2921 | #ifndef USDT2 |
duke@435 | 2922 | DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID); |
dcubed@3202 | 2923 | #else /* USDT2 */ |
dcubed@3202 | 2924 | DT_RETURN_MARK_DECL(GetStaticFieldID, jfieldID |
dcubed@3202 | 2925 | , HOTSPOT_JNI_GETSTATICFIELDID_RETURN((uintptr_t)_ret_ref)); |
dcubed@3202 | 2926 | #endif /* USDT2 */ |
duke@435 | 2927 | |
duke@435 | 2928 | JNI_ENTRY(jfieldID, jni_GetStaticFieldID(JNIEnv *env, jclass clazz, |
duke@435 | 2929 | const char *name, const char *sig)) |
duke@435 | 2930 | JNIWrapper("GetStaticFieldID"); |
dcubed@3202 | 2931 | #ifndef USDT2 |
duke@435 | 2932 | DTRACE_PROBE4(hotspot_jni, GetStaticFieldID__entry, env, clazz, name, sig); |
dcubed@3202 | 2933 | #else /* USDT2 */ |
dcubed@3202 | 2934 | HOTSPOT_JNI_GETSTATICFIELDID_ENTRY( |
dcubed@3202 | 2935 | env, clazz, (char *) name, (char *) sig); |
dcubed@3202 | 2936 | #endif /* USDT2 */ |
duke@435 | 2937 | jfieldID ret = NULL; |
duke@435 | 2938 | DT_RETURN_MARK(GetStaticFieldID, jfieldID, (const jfieldID&)ret); |
duke@435 | 2939 | |
duke@435 | 2940 | // The class should have been loaded (we have an instance of the class |
duke@435 | 2941 | // passed in) so the field and signature should already be in the symbol |
duke@435 | 2942 | // table. If they're not there, the field doesn't exist. |
coleenp@2497 | 2943 | TempNewSymbol fieldname = SymbolTable::probe(name, (int)strlen(name)); |
coleenp@2497 | 2944 | TempNewSymbol signame = SymbolTable::probe(sig, (int)strlen(sig)); |
coleenp@2497 | 2945 | if (fieldname == NULL || signame == NULL) { |
duke@435 | 2946 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2947 | } |
duke@435 | 2948 | KlassHandle k(THREAD, |
coleenp@4037 | 2949 | java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 2950 | // Make sure class is initialized before handing id's out to static fields |
hseigel@4278 | 2951 | k()->initialize(CHECK_NULL); |
duke@435 | 2952 | |
duke@435 | 2953 | fieldDescriptor fd; |
hseigel@4278 | 2954 | if (!k()->oop_is_instance() || |
coleenp@4037 | 2955 | !InstanceKlass::cast(k())->find_field(fieldname, signame, true, &fd)) { |
duke@435 | 2956 | THROW_MSG_0(vmSymbols::java_lang_NoSuchFieldError(), (char*) name); |
duke@435 | 2957 | } |
duke@435 | 2958 | |
coleenp@4037 | 2959 | // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the Klass* |
coleenp@4251 | 2960 | JNIid* id = fd.field_holder()->jni_id_for(fd.offset()); |
duke@435 | 2961 | debug_only(id->set_is_static_field_id();) |
duke@435 | 2962 | |
never@2658 | 2963 | debug_only(id->verify(fd.field_holder())); |
duke@435 | 2964 | |
duke@435 | 2965 | ret = jfieldIDWorkaround::to_static_jfieldID(id); |
duke@435 | 2966 | return ret; |
duke@435 | 2967 | JNI_END |
duke@435 | 2968 | |
duke@435 | 2969 | |
duke@435 | 2970 | JNI_ENTRY(jobject, jni_GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)) |
duke@435 | 2971 | JNIWrapper("GetStaticObjectField"); |
dcubed@3202 | 2972 | #ifndef USDT2 |
duke@435 | 2973 | DTRACE_PROBE3(hotspot_jni, GetStaticObjectField__entry, env, clazz, fieldID); |
dcubed@3202 | 2974 | #else /* USDT2 */ |
dcubed@3202 | 2975 | HOTSPOT_JNI_GETSTATICOBJECTFIELD_ENTRY( |
dcubed@3202 | 2976 | env, clazz, (uintptr_t) fieldID); |
dcubed@3202 | 2977 | #endif /* USDT2 */ |
jprovino@4165 | 2978 | #if INCLUDE_JNI_CHECK |
coleenp@4037 | 2979 | DEBUG_ONLY(Klass* param_k = jniCheck::validate_class(thread, clazz);) |
jprovino@4165 | 2980 | #endif // INCLUDE_JNI_CHECK |
duke@435 | 2981 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 2982 | assert(id->is_static_field_id(), "invalid static field id"); |
duke@435 | 2983 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 2984 | // jni_GetField_probe() assumes that is okay to create handles. |
duke@435 | 2985 | if (JvmtiExport::should_post_field_access()) { |
duke@435 | 2986 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); |
duke@435 | 2987 | } |
never@2658 | 2988 | jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset())); |
dcubed@3202 | 2989 | #ifndef USDT2 |
duke@435 | 2990 | DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); |
dcubed@3202 | 2991 | #else /* USDT2 */ |
dcubed@3202 | 2992 | HOTSPOT_JNI_GETSTATICOBJECTFIELD_RETURN( |
dcubed@3202 | 2993 | ret); |
dcubed@3202 | 2994 | #endif /* USDT2 */ |
duke@435 | 2995 | return ret; |
duke@435 | 2996 | JNI_END |
duke@435 | 2997 | |
dcubed@3202 | 2998 | #ifndef USDT2 |
duke@435 | 2999 | #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ |
duke@435 | 3000 | \ |
duke@435 | 3001 | DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return);\ |
duke@435 | 3002 | \ |
duke@435 | 3003 | JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ |
duke@435 | 3004 | JNIWrapper("GetStatic" XSTR(Result) "Field"); \ |
duke@435 | 3005 | DTRACE_PROBE3(hotspot_jni, GetStatic##Result##Field__entry, env, clazz, fieldID);\ |
duke@435 | 3006 | Return ret = 0;\ |
duke@435 | 3007 | DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ |
duke@435 | 3008 | (const Return&)ret);\ |
duke@435 | 3009 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
duke@435 | 3010 | assert(id->is_static_field_id(), "invalid static field id"); \ |
duke@435 | 3011 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 3012 | /* jni_GetField_probe() assumes that is okay to create handles. */ \ |
duke@435 | 3013 | if (JvmtiExport::should_post_field_access()) { \ |
duke@435 | 3014 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ |
duke@435 | 3015 | } \ |
never@2658 | 3016 | ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ |
duke@435 | 3017 | return ret;\ |
duke@435 | 3018 | JNI_END |
duke@435 | 3019 | |
duke@435 | 3020 | DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) |
duke@435 | 3021 | DEFINE_GETSTATICFIELD(jbyte, byte, Byte) |
duke@435 | 3022 | DEFINE_GETSTATICFIELD(jchar, char, Char) |
duke@435 | 3023 | DEFINE_GETSTATICFIELD(jshort, short, Short) |
duke@435 | 3024 | DEFINE_GETSTATICFIELD(jint, int, Int) |
duke@435 | 3025 | DEFINE_GETSTATICFIELD(jlong, long, Long) |
duke@435 | 3026 | DEFINE_GETSTATICFIELD(jfloat, float, Float) |
duke@435 | 3027 | DEFINE_GETSTATICFIELD(jdouble, double, Double) |
duke@435 | 3028 | |
dcubed@3202 | 3029 | #else /* USDT2 */ |
dcubed@3202 | 3030 | |
dcubed@3202 | 3031 | #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result \ |
dcubed@3202 | 3032 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3033 | \ |
dcubed@3202 | 3034 | DT_RETURN_MARK_DECL_FOR(Result, GetStatic##Result##Field, Return \ |
dcubed@3202 | 3035 | , ReturnProbe); \ |
dcubed@3202 | 3036 | \ |
dcubed@3202 | 3037 | JNI_ENTRY(Return, jni_GetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)) \ |
dcubed@3202 | 3038 | JNIWrapper("GetStatic" XSTR(Result) "Field"); \ |
dcubed@3202 | 3039 | EntryProbe; \ |
dcubed@3202 | 3040 | Return ret = 0;\ |
dcubed@3202 | 3041 | DT_RETURN_MARK_FOR(Result, GetStatic##Result##Field, Return, \ |
dcubed@3202 | 3042 | (const Return&)ret);\ |
dcubed@3202 | 3043 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
dcubed@3202 | 3044 | assert(id->is_static_field_id(), "invalid static field id"); \ |
dcubed@3202 | 3045 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 3046 | /* jni_GetField_probe() assumes that is okay to create handles. */ \ |
dcubed@3202 | 3047 | if (JvmtiExport::should_post_field_access()) { \ |
dcubed@3202 | 3048 | JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ |
dcubed@3202 | 3049 | } \ |
dcubed@3202 | 3050 | ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \ |
dcubed@3202 | 3051 | return ret;\ |
dcubed@3202 | 3052 | JNI_END |
dcubed@3202 | 3053 | |
dcubed@3202 | 3054 | DEFINE_GETSTATICFIELD(jboolean, bool, Boolean |
dcubed@3202 | 3055 | , HOTSPOT_JNI_GETSTATICBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBOOLEANFIELD_RETURN(_ret_ref)) |
dcubed@3202 | 3056 | DEFINE_GETSTATICFIELD(jbyte, byte, Byte |
dcubed@3202 | 3057 | , HOTSPOT_JNI_GETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICBYTEFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3058 | DEFINE_GETSTATICFIELD(jchar, char, Char |
dcubed@3202 | 3059 | , HOTSPOT_JNI_GETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICCHARFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3060 | DEFINE_GETSTATICFIELD(jshort, short, Short |
dcubed@3202 | 3061 | , HOTSPOT_JNI_GETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICSHORTFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3062 | DEFINE_GETSTATICFIELD(jint, int, Int |
dcubed@3202 | 3063 | , HOTSPOT_JNI_GETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICINTFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3064 | DEFINE_GETSTATICFIELD(jlong, long, Long |
dcubed@3202 | 3065 | , HOTSPOT_JNI_GETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICLONGFIELD_RETURN(_ret_ref) ) |
dcubed@3202 | 3066 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3067 | DEFINE_GETSTATICFIELD(jfloat, float, Float |
dcubed@3202 | 3068 | , HOTSPOT_JNI_GETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICFLOATFIELD_RETURN() ) |
dcubed@3202 | 3069 | DEFINE_GETSTATICFIELD(jdouble, double, Double |
dcubed@3202 | 3070 | , HOTSPOT_JNI_GETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), HOTSPOT_JNI_GETSTATICDOUBLEFIELD_RETURN() ) |
dcubed@3202 | 3071 | #endif /* USDT2 */ |
duke@435 | 3072 | |
duke@435 | 3073 | JNI_ENTRY(void, jni_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)) |
duke@435 | 3074 | JNIWrapper("SetStaticObjectField"); |
dcubed@3202 | 3075 | #ifndef USDT2 |
duke@435 | 3076 | DTRACE_PROBE4(hotspot_jni, SetStaticObjectField__entry, env, clazz, fieldID, value); |
dcubed@3202 | 3077 | #else /* USDT2 */ |
dcubed@3202 | 3078 | HOTSPOT_JNI_SETSTATICOBJECTFIELD_ENTRY( |
dcubed@3202 | 3079 | env, clazz, (uintptr_t) fieldID, value); |
dcubed@3202 | 3080 | #endif /* USDT2 */ |
duke@435 | 3081 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); |
duke@435 | 3082 | assert(id->is_static_field_id(), "invalid static field id"); |
duke@435 | 3083 | // Keep JVMTI addition small and only check enabled flag here. |
duke@435 | 3084 | // jni_SetField_probe() assumes that is okay to create handles. |
duke@435 | 3085 | if (JvmtiExport::should_post_field_modification()) { |
duke@435 | 3086 | jvalue field_value; |
duke@435 | 3087 | field_value.l = value; |
duke@435 | 3088 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); |
duke@435 | 3089 | } |
never@2658 | 3090 | id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value)); |
dcubed@3202 | 3091 | #ifndef USDT2 |
duke@435 | 3092 | DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); |
dcubed@3202 | 3093 | #else /* USDT2 */ |
dcubed@3202 | 3094 | HOTSPOT_JNI_SETSTATICOBJECTFIELD_RETURN( |
dcubed@3202 | 3095 | ); |
dcubed@3202 | 3096 | #endif /* USDT2 */ |
duke@435 | 3097 | JNI_END |
duke@435 | 3098 | |
duke@435 | 3099 | |
dcubed@3202 | 3100 | #ifndef USDT2 |
duke@435 | 3101 | #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ |
duke@435 | 3102 | \ |
duke@435 | 3103 | JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ |
duke@435 | 3104 | JNIWrapper("SetStatic" XSTR(Result) "Field"); \ |
coleenp@4148 | 3105 | FP_SELECT_##Result( \ |
coleenp@4148 | 3106 | DTRACE_PROBE4(hotspot_jni, SetStatic##Result##Field__entry, env, clazz, fieldID, value), \ |
coleenp@4148 | 3107 | DTRACE_PROBE3(hotspot_jni, SetStatic##Result##Field__entry, env, clazz, fieldID)); \ |
duke@435 | 3108 | \ |
duke@435 | 3109 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
duke@435 | 3110 | assert(id->is_static_field_id(), "invalid static field id"); \ |
duke@435 | 3111 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
duke@435 | 3112 | /* jni_SetField_probe() assumes that is okay to create handles. */ \ |
duke@435 | 3113 | if (JvmtiExport::should_post_field_modification()) { \ |
duke@435 | 3114 | jvalue field_value; \ |
duke@435 | 3115 | field_value.unionType = value; \ |
duke@435 | 3116 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ |
duke@435 | 3117 | } \ |
never@2658 | 3118 | id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ |
duke@435 | 3119 | DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ |
duke@435 | 3120 | JNI_END |
duke@435 | 3121 | |
duke@435 | 3122 | DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) |
duke@435 | 3123 | DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) |
duke@435 | 3124 | DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c) |
duke@435 | 3125 | DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s) |
duke@435 | 3126 | DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i) |
duke@435 | 3127 | DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j) |
duke@435 | 3128 | DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f) |
duke@435 | 3129 | DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d) |
duke@435 | 3130 | |
dcubed@3202 | 3131 | #else /* USDT2 */ |
dcubed@3202 | 3132 | |
dcubed@3202 | 3133 | #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType \ |
dcubed@3202 | 3134 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3135 | \ |
dcubed@3202 | 3136 | JNI_ENTRY(void, jni_SetStatic##Result##Field(JNIEnv *env, jclass clazz, jfieldID fieldID, Argument value)) \ |
dcubed@3202 | 3137 | JNIWrapper("SetStatic" XSTR(Result) "Field"); \ |
dcubed@3202 | 3138 | EntryProbe; \ |
dcubed@3202 | 3139 | \ |
dcubed@3202 | 3140 | JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); \ |
dcubed@3202 | 3141 | assert(id->is_static_field_id(), "invalid static field id"); \ |
dcubed@3202 | 3142 | /* Keep JVMTI addition small and only check enabled flag here. */ \ |
dcubed@3202 | 3143 | /* jni_SetField_probe() assumes that is okay to create handles. */ \ |
dcubed@3202 | 3144 | if (JvmtiExport::should_post_field_modification()) { \ |
dcubed@3202 | 3145 | jvalue field_value; \ |
dcubed@3202 | 3146 | field_value.unionType = value; \ |
dcubed@3202 | 3147 | JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ |
dcubed@3202 | 3148 | } \ |
dcubed@3202 | 3149 | id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \ |
dcubed@3202 | 3150 | ReturnProbe;\ |
dcubed@3202 | 3151 | JNI_END |
dcubed@3202 | 3152 | |
dcubed@3202 | 3153 | DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z |
dcubed@3202 | 3154 | , HOTSPOT_JNI_SETBOOLEANFIELD_ENTRY(env, clazz, (uintptr_t)fieldID, value), |
dcubed@3202 | 3155 | HOTSPOT_JNI_SETBOOLEANFIELD_RETURN()) |
dcubed@3202 | 3156 | DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b |
dcubed@3202 | 3157 | , HOTSPOT_JNI_SETSTATICBYTEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3158 | HOTSPOT_JNI_SETSTATICBYTEFIELD_RETURN()) |
dcubed@3202 | 3159 | DEFINE_SETSTATICFIELD(jchar, char, Char, 'C', c |
dcubed@3202 | 3160 | , HOTSPOT_JNI_SETSTATICCHARFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3161 | HOTSPOT_JNI_SETSTATICCHARFIELD_RETURN()) |
dcubed@3202 | 3162 | DEFINE_SETSTATICFIELD(jshort, short, Short, 'S', s |
dcubed@3202 | 3163 | , HOTSPOT_JNI_SETSTATICSHORTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3164 | HOTSPOT_JNI_SETSTATICSHORTFIELD_RETURN()) |
dcubed@3202 | 3165 | DEFINE_SETSTATICFIELD(jint, int, Int, 'I', i |
dcubed@3202 | 3166 | , HOTSPOT_JNI_SETSTATICINTFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3167 | HOTSPOT_JNI_SETSTATICINTFIELD_RETURN()) |
dcubed@3202 | 3168 | DEFINE_SETSTATICFIELD(jlong, long, Long, 'J', j |
dcubed@3202 | 3169 | , HOTSPOT_JNI_SETSTATICLONGFIELD_ENTRY(env, clazz, (uintptr_t) fieldID, value), |
dcubed@3202 | 3170 | HOTSPOT_JNI_SETSTATICLONGFIELD_RETURN()) |
dcubed@3202 | 3171 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3172 | DEFINE_SETSTATICFIELD(jfloat, float, Float, 'F', f |
dcubed@3202 | 3173 | , HOTSPOT_JNI_SETSTATICFLOATFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), |
dcubed@3202 | 3174 | HOTSPOT_JNI_SETSTATICFLOATFIELD_RETURN()) |
dcubed@3202 | 3175 | DEFINE_SETSTATICFIELD(jdouble, double, Double, 'D', d |
dcubed@3202 | 3176 | , HOTSPOT_JNI_SETSTATICDOUBLEFIELD_ENTRY(env, clazz, (uintptr_t) fieldID), |
dcubed@3202 | 3177 | HOTSPOT_JNI_SETSTATICDOUBLEFIELD_RETURN()) |
dcubed@3202 | 3178 | #endif /* USDT2 */ |
duke@435 | 3179 | |
duke@435 | 3180 | // |
duke@435 | 3181 | // String Operations |
duke@435 | 3182 | // |
duke@435 | 3183 | |
duke@435 | 3184 | // Unicode Interface |
duke@435 | 3185 | |
dcubed@3202 | 3186 | #ifndef USDT2 |
duke@435 | 3187 | DT_RETURN_MARK_DECL(NewString, jstring); |
dcubed@3202 | 3188 | #else /* USDT2 */ |
dcubed@3202 | 3189 | DT_RETURN_MARK_DECL(NewString, jstring |
dcubed@3202 | 3190 | , HOTSPOT_JNI_NEWSTRING_RETURN(_ret_ref)); |
dcubed@3202 | 3191 | #endif /* USDT2 */ |
duke@435 | 3192 | |
duke@435 | 3193 | JNI_ENTRY(jstring, jni_NewString(JNIEnv *env, const jchar *unicodeChars, jsize len)) |
duke@435 | 3194 | JNIWrapper("NewString"); |
dcubed@3202 | 3195 | #ifndef USDT2 |
duke@435 | 3196 | DTRACE_PROBE3(hotspot_jni, NewString__entry, env, unicodeChars, len); |
dcubed@3202 | 3197 | #else /* USDT2 */ |
dcubed@3202 | 3198 | HOTSPOT_JNI_NEWSTRING_ENTRY( |
dcubed@3202 | 3199 | env, (uint16_t *) unicodeChars, len); |
dcubed@3202 | 3200 | #endif /* USDT2 */ |
duke@435 | 3201 | jstring ret = NULL; |
duke@435 | 3202 | DT_RETURN_MARK(NewString, jstring, (const jstring&)ret); |
duke@435 | 3203 | oop string=java_lang_String::create_oop_from_unicode((jchar*) unicodeChars, len, CHECK_NULL); |
duke@435 | 3204 | ret = (jstring) JNIHandles::make_local(env, string); |
duke@435 | 3205 | return ret; |
duke@435 | 3206 | JNI_END |
duke@435 | 3207 | |
duke@435 | 3208 | |
duke@435 | 3209 | JNI_QUICK_ENTRY(jsize, jni_GetStringLength(JNIEnv *env, jstring string)) |
duke@435 | 3210 | JNIWrapper("GetStringLength"); |
dcubed@3202 | 3211 | #ifndef USDT2 |
duke@435 | 3212 | DTRACE_PROBE2(hotspot_jni, GetStringLength__entry, env, string); |
dcubed@3202 | 3213 | #else /* USDT2 */ |
dcubed@3202 | 3214 | HOTSPOT_JNI_GETSTRINGLENGTH_ENTRY( |
dcubed@3202 | 3215 | env, string); |
dcubed@3202 | 3216 | #endif /* USDT2 */ |
duke@435 | 3217 | jsize ret = java_lang_String::length(JNIHandles::resolve_non_null(string)); |
dcubed@3202 | 3218 | #ifndef USDT2 |
duke@435 | 3219 | DTRACE_PROBE1(hotspot_jni, GetStringLength__return, ret); |
dcubed@3202 | 3220 | #else /* USDT2 */ |
dcubed@3202 | 3221 | HOTSPOT_JNI_GETSTRINGLENGTH_RETURN( |
dcubed@3202 | 3222 | ret); |
dcubed@3202 | 3223 | #endif /* USDT2 */ |
duke@435 | 3224 | return ret; |
duke@435 | 3225 | JNI_END |
duke@435 | 3226 | |
duke@435 | 3227 | |
duke@435 | 3228 | JNI_QUICK_ENTRY(const jchar*, jni_GetStringChars( |
duke@435 | 3229 | JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 3230 | JNIWrapper("GetStringChars"); |
dcubed@3202 | 3231 | #ifndef USDT2 |
duke@435 | 3232 | DTRACE_PROBE3(hotspot_jni, GetStringChars__entry, env, string, isCopy); |
dcubed@3202 | 3233 | #else /* USDT2 */ |
dcubed@3202 | 3234 | HOTSPOT_JNI_GETSTRINGCHARS_ENTRY( |
dcubed@3202 | 3235 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 3236 | #endif /* USDT2 */ |
duke@435 | 3237 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 3238 | int s_len = java_lang_String::length(s); |
duke@435 | 3239 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 3240 | int s_offset = java_lang_String::offset(s); |
dsimms@5577 | 3241 | jchar* buf = NEW_C_HEAP_ARRAY_RETURN_NULL(jchar, s_len + 1, mtInternal); // add one for zero termination |
dsimms@5577 | 3242 | /* JNI Specification states return NULL on OOM */ |
dsimms@5577 | 3243 | if (buf != NULL) { |
dsimms@5577 | 3244 | if (s_len > 0) { |
dsimms@5577 | 3245 | memcpy(buf, s_value->char_at_addr(s_offset), sizeof(jchar)*s_len); |
dsimms@5577 | 3246 | } |
dsimms@5577 | 3247 | buf[s_len] = 0; |
dsimms@5577 | 3248 | //%note jni_5 |
dsimms@5577 | 3249 | if (isCopy != NULL) { |
dsimms@5577 | 3250 | *isCopy = JNI_TRUE; |
dsimms@5577 | 3251 | } |
duke@435 | 3252 | } |
dcubed@3202 | 3253 | #ifndef USDT2 |
duke@435 | 3254 | DTRACE_PROBE1(hotspot_jni, GetStringChars__return, buf); |
dcubed@3202 | 3255 | #else /* USDT2 */ |
dcubed@3202 | 3256 | HOTSPOT_JNI_GETSTRINGCHARS_RETURN( |
dcubed@3202 | 3257 | buf); |
dcubed@3202 | 3258 | #endif /* USDT2 */ |
duke@435 | 3259 | return buf; |
duke@435 | 3260 | JNI_END |
duke@435 | 3261 | |
duke@435 | 3262 | |
duke@435 | 3263 | JNI_QUICK_ENTRY(void, jni_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)) |
duke@435 | 3264 | JNIWrapper("ReleaseStringChars"); |
dcubed@3202 | 3265 | #ifndef USDT2 |
duke@435 | 3266 | DTRACE_PROBE3(hotspot_jni, ReleaseStringChars__entry, env, str, chars); |
dcubed@3202 | 3267 | #else /* USDT2 */ |
dcubed@3202 | 3268 | HOTSPOT_JNI_RELEASESTRINGCHARS_ENTRY( |
dcubed@3202 | 3269 | env, str, (uint16_t *) chars); |
dcubed@3202 | 3270 | #endif /* USDT2 */ |
duke@435 | 3271 | //%note jni_6 |
duke@435 | 3272 | if (chars != NULL) { |
duke@435 | 3273 | // Since String objects are supposed to be immutable, don't copy any |
duke@435 | 3274 | // new data back. A bad user will have to go after the char array. |
duke@435 | 3275 | FreeHeap((void*) chars); |
duke@435 | 3276 | } |
dcubed@3202 | 3277 | #ifndef USDT2 |
duke@435 | 3278 | DTRACE_PROBE(hotspot_jni, ReleaseStringChars__return); |
dcubed@3202 | 3279 | #else /* USDT2 */ |
dcubed@3202 | 3280 | HOTSPOT_JNI_RELEASESTRINGCHARS_RETURN( |
dcubed@3202 | 3281 | ); |
dcubed@3202 | 3282 | #endif /* USDT2 */ |
duke@435 | 3283 | JNI_END |
duke@435 | 3284 | |
duke@435 | 3285 | |
duke@435 | 3286 | // UTF Interface |
duke@435 | 3287 | |
dcubed@3202 | 3288 | #ifndef USDT2 |
duke@435 | 3289 | DT_RETURN_MARK_DECL(NewStringUTF, jstring); |
dcubed@3202 | 3290 | #else /* USDT2 */ |
dcubed@3202 | 3291 | DT_RETURN_MARK_DECL(NewStringUTF, jstring |
dcubed@3202 | 3292 | , HOTSPOT_JNI_NEWSTRINGUTF_RETURN(_ret_ref)); |
dcubed@3202 | 3293 | #endif /* USDT2 */ |
duke@435 | 3294 | |
duke@435 | 3295 | JNI_ENTRY(jstring, jni_NewStringUTF(JNIEnv *env, const char *bytes)) |
duke@435 | 3296 | JNIWrapper("NewStringUTF"); |
dcubed@3202 | 3297 | #ifndef USDT2 |
duke@435 | 3298 | DTRACE_PROBE2(hotspot_jni, NewStringUTF__entry, env, bytes); |
dcubed@3202 | 3299 | #else /* USDT2 */ |
dcubed@3202 | 3300 | HOTSPOT_JNI_NEWSTRINGUTF_ENTRY( |
dcubed@3202 | 3301 | env, (char *) bytes); |
dcubed@3202 | 3302 | #endif /* USDT2 */ |
duke@435 | 3303 | jstring ret; |
duke@435 | 3304 | DT_RETURN_MARK(NewStringUTF, jstring, (const jstring&)ret); |
duke@435 | 3305 | |
duke@435 | 3306 | oop result = java_lang_String::create_oop_from_str((char*) bytes, CHECK_NULL); |
duke@435 | 3307 | ret = (jstring) JNIHandles::make_local(env, result); |
duke@435 | 3308 | return ret; |
duke@435 | 3309 | JNI_END |
duke@435 | 3310 | |
duke@435 | 3311 | |
duke@435 | 3312 | JNI_ENTRY(jsize, jni_GetStringUTFLength(JNIEnv *env, jstring string)) |
duke@435 | 3313 | JNIWrapper("GetStringUTFLength"); |
dcubed@3202 | 3314 | #ifndef USDT2 |
duke@435 | 3315 | DTRACE_PROBE2(hotspot_jni, GetStringUTFLength__entry, env, string); |
dcubed@3202 | 3316 | #else /* USDT2 */ |
dcubed@3202 | 3317 | HOTSPOT_JNI_GETSTRINGUTFLENGTH_ENTRY( |
dcubed@3202 | 3318 | env, string); |
dcubed@3202 | 3319 | #endif /* USDT2 */ |
duke@435 | 3320 | jsize ret = java_lang_String::utf8_length(JNIHandles::resolve_non_null(string)); |
dcubed@3202 | 3321 | #ifndef USDT2 |
duke@435 | 3322 | DTRACE_PROBE1(hotspot_jni, GetStringUTFLength__return, ret); |
dcubed@3202 | 3323 | #else /* USDT2 */ |
dcubed@3202 | 3324 | HOTSPOT_JNI_GETSTRINGUTFLENGTH_RETURN( |
dcubed@3202 | 3325 | ret); |
dcubed@3202 | 3326 | #endif /* USDT2 */ |
duke@435 | 3327 | return ret; |
duke@435 | 3328 | JNI_END |
duke@435 | 3329 | |
duke@435 | 3330 | |
duke@435 | 3331 | JNI_ENTRY(const char*, jni_GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 3332 | JNIWrapper("GetStringUTFChars"); |
dcubed@3202 | 3333 | #ifndef USDT2 |
duke@435 | 3334 | DTRACE_PROBE3(hotspot_jni, GetStringUTFChars__entry, env, string, isCopy); |
dcubed@3202 | 3335 | #else /* USDT2 */ |
dcubed@3202 | 3336 | HOTSPOT_JNI_GETSTRINGUTFCHARS_ENTRY( |
dcubed@3202 | 3337 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 3338 | #endif /* USDT2 */ |
sla@2331 | 3339 | oop java_string = JNIHandles::resolve_non_null(string); |
sla@2331 | 3340 | size_t length = java_lang_String::utf8_length(java_string); |
dsimms@5577 | 3341 | /* JNI Specification states return NULL on OOM */ |
dsimms@5577 | 3342 | char* result = AllocateHeap(length + 1, mtInternal, 0, AllocFailStrategy::RETURN_NULL); |
dsimms@5577 | 3343 | if (result != NULL) { |
dsimms@5577 | 3344 | java_lang_String::as_utf8_string(java_string, result, (int) length + 1); |
dsimms@5577 | 3345 | if (isCopy != NULL) { |
dsimms@5577 | 3346 | *isCopy = JNI_TRUE; |
dsimms@5577 | 3347 | } |
dsimms@5577 | 3348 | } |
dcubed@3202 | 3349 | #ifndef USDT2 |
duke@435 | 3350 | DTRACE_PROBE1(hotspot_jni, GetStringUTFChars__return, result); |
dcubed@3202 | 3351 | #else /* USDT2 */ |
dcubed@3202 | 3352 | HOTSPOT_JNI_GETSTRINGUTFCHARS_RETURN( |
dcubed@3202 | 3353 | result); |
dcubed@3202 | 3354 | #endif /* USDT2 */ |
duke@435 | 3355 | return result; |
duke@435 | 3356 | JNI_END |
duke@435 | 3357 | |
duke@435 | 3358 | |
duke@435 | 3359 | JNI_LEAF(void, jni_ReleaseStringUTFChars(JNIEnv *env, jstring str, const char *chars)) |
duke@435 | 3360 | JNIWrapper("ReleaseStringUTFChars"); |
dcubed@3202 | 3361 | #ifndef USDT2 |
duke@435 | 3362 | DTRACE_PROBE3(hotspot_jni, ReleaseStringUTFChars__entry, env, str, chars); |
dcubed@3202 | 3363 | #else /* USDT2 */ |
dcubed@3202 | 3364 | HOTSPOT_JNI_RELEASESTRINGUTFCHARS_ENTRY( |
dcubed@3202 | 3365 | env, str, (char *) chars); |
dcubed@3202 | 3366 | #endif /* USDT2 */ |
duke@435 | 3367 | if (chars != NULL) { |
duke@435 | 3368 | FreeHeap((char*) chars); |
duke@435 | 3369 | } |
dcubed@3202 | 3370 | #ifndef USDT2 |
duke@435 | 3371 | DTRACE_PROBE(hotspot_jni, ReleaseStringUTFChars__return); |
dcubed@3202 | 3372 | #else /* USDT2 */ |
dcubed@3202 | 3373 | HOTSPOT_JNI_RELEASESTRINGUTFCHARS_RETURN( |
dcubed@3202 | 3374 | ); |
dcubed@3202 | 3375 | #endif /* USDT2 */ |
duke@435 | 3376 | JNI_END |
duke@435 | 3377 | |
duke@435 | 3378 | |
duke@435 | 3379 | JNI_QUICK_ENTRY(jsize, jni_GetArrayLength(JNIEnv *env, jarray array)) |
duke@435 | 3380 | JNIWrapper("GetArrayLength"); |
dcubed@3202 | 3381 | #ifndef USDT2 |
duke@435 | 3382 | DTRACE_PROBE2(hotspot_jni, GetArrayLength__entry, env, array); |
dcubed@3202 | 3383 | #else /* USDT2 */ |
dcubed@3202 | 3384 | HOTSPOT_JNI_GETARRAYLENGTH_ENTRY( |
dcubed@3202 | 3385 | env, array); |
dcubed@3202 | 3386 | #endif /* USDT2 */ |
duke@435 | 3387 | arrayOop a = arrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3388 | assert(a->is_array(), "must be array"); |
duke@435 | 3389 | jsize ret = a->length(); |
dcubed@3202 | 3390 | #ifndef USDT2 |
duke@435 | 3391 | DTRACE_PROBE1(hotspot_jni, GetArrayLength__return, ret); |
dcubed@3202 | 3392 | #else /* USDT2 */ |
dcubed@3202 | 3393 | HOTSPOT_JNI_GETARRAYLENGTH_RETURN( |
dcubed@3202 | 3394 | ret); |
dcubed@3202 | 3395 | #endif /* USDT2 */ |
duke@435 | 3396 | return ret; |
duke@435 | 3397 | JNI_END |
duke@435 | 3398 | |
duke@435 | 3399 | |
duke@435 | 3400 | // |
duke@435 | 3401 | // Object Array Operations |
duke@435 | 3402 | // |
duke@435 | 3403 | |
dcubed@3202 | 3404 | #ifndef USDT2 |
duke@435 | 3405 | DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray); |
dcubed@3202 | 3406 | #else /* USDT2 */ |
dcubed@3202 | 3407 | DT_RETURN_MARK_DECL(NewObjectArray, jobjectArray |
dcubed@3202 | 3408 | , HOTSPOT_JNI_NEWOBJECTARRAY_RETURN(_ret_ref)); |
dcubed@3202 | 3409 | #endif /* USDT2 */ |
duke@435 | 3410 | |
duke@435 | 3411 | JNI_ENTRY(jobjectArray, jni_NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)) |
duke@435 | 3412 | JNIWrapper("NewObjectArray"); |
dcubed@3202 | 3413 | #ifndef USDT2 |
duke@435 | 3414 | DTRACE_PROBE4(hotspot_jni, NewObjectArray__entry, env, length, elementClass, initialElement); |
dcubed@3202 | 3415 | #else /* USDT2 */ |
dcubed@3202 | 3416 | HOTSPOT_JNI_NEWOBJECTARRAY_ENTRY( |
dcubed@3202 | 3417 | env, length, elementClass, initialElement); |
dcubed@3202 | 3418 | #endif /* USDT2 */ |
duke@435 | 3419 | jobjectArray ret = NULL; |
duke@435 | 3420 | DT_RETURN_MARK(NewObjectArray, jobjectArray, (const jobjectArray&)ret); |
coleenp@4037 | 3421 | KlassHandle ek(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(elementClass))); |
hseigel@4278 | 3422 | Klass* ako = ek()->array_klass(CHECK_NULL); |
duke@435 | 3423 | KlassHandle ak = KlassHandle(THREAD, ako); |
coleenp@4142 | 3424 | ObjArrayKlass::cast(ak())->initialize(CHECK_NULL); |
coleenp@4142 | 3425 | objArrayOop result = ObjArrayKlass::cast(ak())->allocate(length, CHECK_NULL); |
duke@435 | 3426 | oop initial_value = JNIHandles::resolve(initialElement); |
duke@435 | 3427 | if (initial_value != NULL) { // array already initialized with NULL |
duke@435 | 3428 | for (int index = 0; index < length; index++) { |
duke@435 | 3429 | result->obj_at_put(index, initial_value); |
duke@435 | 3430 | } |
duke@435 | 3431 | } |
duke@435 | 3432 | ret = (jobjectArray) JNIHandles::make_local(env, result); |
duke@435 | 3433 | return ret; |
duke@435 | 3434 | JNI_END |
duke@435 | 3435 | |
dcubed@3202 | 3436 | #ifndef USDT2 |
duke@435 | 3437 | DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject); |
dcubed@3202 | 3438 | #else /* USDT2 */ |
dcubed@3202 | 3439 | DT_RETURN_MARK_DECL(GetObjectArrayElement, jobject |
dcubed@3202 | 3440 | , HOTSPOT_JNI_GETOBJECTARRAYELEMENT_RETURN(_ret_ref)); |
dcubed@3202 | 3441 | #endif /* USDT2 */ |
duke@435 | 3442 | |
duke@435 | 3443 | JNI_ENTRY(jobject, jni_GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)) |
duke@435 | 3444 | JNIWrapper("GetObjectArrayElement"); |
dcubed@3202 | 3445 | #ifndef USDT2 |
duke@435 | 3446 | DTRACE_PROBE3(hotspot_jni, GetObjectArrayElement__entry, env, array, index); |
dcubed@3202 | 3447 | #else /* USDT2 */ |
dcubed@3202 | 3448 | HOTSPOT_JNI_GETOBJECTARRAYELEMENT_ENTRY( |
dcubed@3202 | 3449 | env, array, index); |
dcubed@3202 | 3450 | #endif /* USDT2 */ |
duke@435 | 3451 | jobject ret = NULL; |
duke@435 | 3452 | DT_RETURN_MARK(GetObjectArrayElement, jobject, (const jobject&)ret); |
duke@435 | 3453 | objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3454 | if (a->is_within_bounds(index)) { |
kamg@1469 | 3455 | ret = JNIHandles::make_local(env, a->obj_at(index)); |
duke@435 | 3456 | return ret; |
duke@435 | 3457 | } else { |
duke@435 | 3458 | char buf[jintAsStringSize]; |
duke@435 | 3459 | sprintf(buf, "%d", index); |
duke@435 | 3460 | THROW_MSG_0(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); |
duke@435 | 3461 | } |
duke@435 | 3462 | JNI_END |
duke@435 | 3463 | |
dcubed@3202 | 3464 | #ifndef USDT2 |
duke@435 | 3465 | DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement); |
dcubed@3202 | 3466 | #else /* USDT2 */ |
dcubed@3202 | 3467 | DT_VOID_RETURN_MARK_DECL(SetObjectArrayElement |
dcubed@3202 | 3468 | , HOTSPOT_JNI_SETOBJECTARRAYELEMENT_RETURN()); |
dcubed@3202 | 3469 | #endif /* USDT2 */ |
duke@435 | 3470 | |
duke@435 | 3471 | JNI_ENTRY(void, jni_SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject value)) |
duke@435 | 3472 | JNIWrapper("SetObjectArrayElement"); |
dcubed@3202 | 3473 | #ifndef USDT2 |
duke@435 | 3474 | DTRACE_PROBE4(hotspot_jni, SetObjectArrayElement__entry, env, array, index, value); |
dcubed@3202 | 3475 | #else /* USDT2 */ |
dcubed@3202 | 3476 | HOTSPOT_JNI_SETOBJECTARRAYELEMENT_ENTRY( |
dcubed@3202 | 3477 | env, array, index, value); |
dcubed@3202 | 3478 | #endif /* USDT2 */ |
duke@435 | 3479 | DT_VOID_RETURN_MARK(SetObjectArrayElement); |
duke@435 | 3480 | |
duke@435 | 3481 | objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(array)); |
duke@435 | 3482 | oop v = JNIHandles::resolve(value); |
duke@435 | 3483 | if (a->is_within_bounds(index)) { |
coleenp@4142 | 3484 | if (v == NULL || v->is_a(ObjArrayKlass::cast(a->klass())->element_klass())) { |
duke@435 | 3485 | a->obj_at_put(index, v); |
duke@435 | 3486 | } else { |
duke@435 | 3487 | THROW(vmSymbols::java_lang_ArrayStoreException()); |
duke@435 | 3488 | } |
duke@435 | 3489 | } else { |
duke@435 | 3490 | char buf[jintAsStringSize]; |
duke@435 | 3491 | sprintf(buf, "%d", index); |
duke@435 | 3492 | THROW_MSG(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), buf); |
duke@435 | 3493 | } |
duke@435 | 3494 | JNI_END |
duke@435 | 3495 | |
duke@435 | 3496 | |
dcubed@3202 | 3497 | #ifndef USDT2 |
duke@435 | 3498 | #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result) \ |
duke@435 | 3499 | \ |
dcubed@3202 | 3500 | DT_RETURN_MARK_DECL(New##Result##Array, Return); \ |
duke@435 | 3501 | \ |
duke@435 | 3502 | JNI_ENTRY(Return, \ |
duke@435 | 3503 | jni_New##Result##Array(JNIEnv *env, jsize len)) \ |
duke@435 | 3504 | JNIWrapper("New" XSTR(Result) "Array"); \ |
duke@435 | 3505 | DTRACE_PROBE2(hotspot_jni, New##Result##Array__entry, env, len);\ |
duke@435 | 3506 | Return ret = NULL;\ |
kamg@1469 | 3507 | DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
duke@435 | 3508 | \ |
duke@435 | 3509 | oop obj= oopFactory::Allocator(len, CHECK_0); \ |
duke@435 | 3510 | ret = (Return) JNIHandles::make_local(env, obj); \ |
duke@435 | 3511 | return ret;\ |
duke@435 | 3512 | JNI_END |
duke@435 | 3513 | |
duke@435 | 3514 | DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean) |
duke@435 | 3515 | DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte) |
duke@435 | 3516 | DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short) |
duke@435 | 3517 | DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char) |
duke@435 | 3518 | DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int) |
duke@435 | 3519 | DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long) |
duke@435 | 3520 | DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float) |
duke@435 | 3521 | DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double) |
duke@435 | 3522 | |
dcubed@3202 | 3523 | #else /* USDT2 */ |
dcubed@3202 | 3524 | |
dcubed@3202 | 3525 | #define DEFINE_NEWSCALARARRAY(Return,Allocator,Result \ |
dcubed@3202 | 3526 | ,EntryProbe,ReturnProbe) \ |
dcubed@3202 | 3527 | \ |
dcubed@3202 | 3528 | DT_RETURN_MARK_DECL(New##Result##Array, Return \ |
dcubed@3202 | 3529 | , ReturnProbe); \ |
dcubed@3202 | 3530 | \ |
dcubed@3202 | 3531 | JNI_ENTRY(Return, \ |
dcubed@3202 | 3532 | jni_New##Result##Array(JNIEnv *env, jsize len)) \ |
dcubed@3202 | 3533 | JNIWrapper("New" XSTR(Result) "Array"); \ |
dcubed@3202 | 3534 | EntryProbe; \ |
dcubed@3202 | 3535 | Return ret = NULL;\ |
dcubed@3202 | 3536 | DT_RETURN_MARK(New##Result##Array, Return, (const Return&)ret);\ |
dcubed@3202 | 3537 | \ |
dcubed@3202 | 3538 | oop obj= oopFactory::Allocator(len, CHECK_0); \ |
dcubed@3202 | 3539 | ret = (Return) JNIHandles::make_local(env, obj); \ |
dcubed@3202 | 3540 | return ret;\ |
dcubed@3202 | 3541 | JNI_END |
dcubed@3202 | 3542 | |
dcubed@3202 | 3543 | DEFINE_NEWSCALARARRAY(jbooleanArray, new_boolArray, Boolean, |
dcubed@3202 | 3544 | HOTSPOT_JNI_NEWBOOLEANARRAY_ENTRY(env, len), |
dcubed@3202 | 3545 | HOTSPOT_JNI_NEWBOOLEANARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3546 | DEFINE_NEWSCALARARRAY(jbyteArray, new_byteArray, Byte, |
dcubed@3202 | 3547 | HOTSPOT_JNI_NEWBYTEARRAY_ENTRY(env, len), |
dcubed@3202 | 3548 | HOTSPOT_JNI_NEWBYTEARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3549 | DEFINE_NEWSCALARARRAY(jshortArray, new_shortArray, Short, |
dcubed@3202 | 3550 | HOTSPOT_JNI_NEWSHORTARRAY_ENTRY(env, len), |
dcubed@3202 | 3551 | HOTSPOT_JNI_NEWSHORTARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3552 | DEFINE_NEWSCALARARRAY(jcharArray, new_charArray, Char, |
dcubed@3202 | 3553 | HOTSPOT_JNI_NEWCHARARRAY_ENTRY(env, len), |
dcubed@3202 | 3554 | HOTSPOT_JNI_NEWCHARARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3555 | DEFINE_NEWSCALARARRAY(jintArray, new_intArray, Int, |
dcubed@3202 | 3556 | HOTSPOT_JNI_NEWINTARRAY_ENTRY(env, len), |
dcubed@3202 | 3557 | HOTSPOT_JNI_NEWINTARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3558 | DEFINE_NEWSCALARARRAY(jlongArray, new_longArray, Long, |
dcubed@3202 | 3559 | HOTSPOT_JNI_NEWLONGARRAY_ENTRY(env, len), |
dcubed@3202 | 3560 | HOTSPOT_JNI_NEWLONGARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3561 | DEFINE_NEWSCALARARRAY(jfloatArray, new_singleArray, Float, |
dcubed@3202 | 3562 | HOTSPOT_JNI_NEWFLOATARRAY_ENTRY(env, len), |
dcubed@3202 | 3563 | HOTSPOT_JNI_NEWFLOATARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3564 | DEFINE_NEWSCALARARRAY(jdoubleArray, new_doubleArray, Double, |
dcubed@3202 | 3565 | HOTSPOT_JNI_NEWDOUBLEARRAY_ENTRY(env, len), |
dcubed@3202 | 3566 | HOTSPOT_JNI_NEWDOUBLEARRAY_RETURN(_ret_ref)) |
dcubed@3202 | 3567 | #endif /* USDT2 */ |
duke@435 | 3568 | |
duke@435 | 3569 | // Return an address which will fault if the caller writes to it. |
duke@435 | 3570 | |
duke@435 | 3571 | static char* get_bad_address() { |
duke@435 | 3572 | static char* bad_address = NULL; |
duke@435 | 3573 | if (bad_address == NULL) { |
duke@435 | 3574 | size_t size = os::vm_allocation_granularity(); |
duke@435 | 3575 | bad_address = os::reserve_memory(size); |
duke@435 | 3576 | if (bad_address != NULL) { |
coleenp@912 | 3577 | os::protect_memory(bad_address, size, os::MEM_PROT_READ, |
coleenp@912 | 3578 | /*is_committed*/false); |
duke@435 | 3579 | } |
duke@435 | 3580 | } |
duke@435 | 3581 | return bad_address; |
duke@435 | 3582 | } |
duke@435 | 3583 | |
duke@435 | 3584 | |
dcubed@3202 | 3585 | #ifndef USDT2 |
duke@435 | 3586 | #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3587 | \ |
duke@435 | 3588 | JNI_QUICK_ENTRY(ElementType*, \ |
duke@435 | 3589 | jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ |
duke@435 | 3590 | JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ |
duke@435 | 3591 | DTRACE_PROBE3(hotspot_jni, Get##Result##ArrayElements__entry, env, array, isCopy);\ |
duke@435 | 3592 | /* allocate an chunk of memory in c land */ \ |
duke@435 | 3593 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3594 | ElementType* result; \ |
duke@435 | 3595 | int len = a->length(); \ |
duke@435 | 3596 | if (len == 0) { \ |
duke@435 | 3597 | /* Empty array: legal but useless, can't return NULL. \ |
duke@435 | 3598 | * Return a pointer to something useless. \ |
duke@435 | 3599 | * Avoid asserts in typeArrayOop. */ \ |
duke@435 | 3600 | result = (ElementType*)get_bad_address(); \ |
duke@435 | 3601 | } else { \ |
dsimms@5577 | 3602 | /* JNI Specification states return NULL on OOM */ \ |
dsimms@5577 | 3603 | result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \ |
dsimms@5577 | 3604 | if (result != NULL) { \ |
dsimms@5577 | 3605 | /* copy the array to the c chunk */ \ |
dsimms@5577 | 3606 | memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
dsimms@5577 | 3607 | if (isCopy) { \ |
dsimms@5577 | 3608 | *isCopy = JNI_TRUE; \ |
dsimms@5577 | 3609 | } \ |
dsimms@5577 | 3610 | } \ |
duke@435 | 3611 | } \ |
duke@435 | 3612 | DTRACE_PROBE1(hotspot_jni, Get##Result##ArrayElements__return, result);\ |
duke@435 | 3613 | return result; \ |
duke@435 | 3614 | JNI_END |
duke@435 | 3615 | |
duke@435 | 3616 | DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3617 | DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3618 | DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) |
duke@435 | 3619 | DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) |
duke@435 | 3620 | DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int) |
duke@435 | 3621 | DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long) |
duke@435 | 3622 | DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) |
duke@435 | 3623 | DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3624 | |
dcubed@3202 | 3625 | #else /* USDT2 */ |
dcubed@3202 | 3626 | |
dcubed@3202 | 3627 | #define DEFINE_GETSCALARARRAYELEMENTS(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3628 | , EntryProbe, ReturnProbe) \ |
dcubed@3202 | 3629 | \ |
dcubed@3202 | 3630 | JNI_QUICK_ENTRY(ElementType*, \ |
dcubed@3202 | 3631 | jni_Get##Result##ArrayElements(JNIEnv *env, ElementType##Array array, jboolean *isCopy)) \ |
dcubed@3202 | 3632 | JNIWrapper("Get" XSTR(Result) "ArrayElements"); \ |
dcubed@3202 | 3633 | EntryProbe; \ |
dcubed@3202 | 3634 | /* allocate an chunk of memory in c land */ \ |
dcubed@3202 | 3635 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3636 | ElementType* result; \ |
dcubed@3202 | 3637 | int len = a->length(); \ |
dcubed@3202 | 3638 | if (len == 0) { \ |
dcubed@3202 | 3639 | /* Empty array: legal but useless, can't return NULL. \ |
dcubed@3202 | 3640 | * Return a pointer to something useless. \ |
dcubed@3202 | 3641 | * Avoid asserts in typeArrayOop. */ \ |
dcubed@3202 | 3642 | result = (ElementType*)get_bad_address(); \ |
dcubed@3202 | 3643 | } else { \ |
dsimms@5577 | 3644 | /* JNI Specification states return NULL on OOM */ \ |
dsimms@5577 | 3645 | result = NEW_C_HEAP_ARRAY_RETURN_NULL(ElementType, len, mtInternal); \ |
dsimms@5577 | 3646 | if (result != NULL) { \ |
dsimms@5577 | 3647 | /* copy the array to the c chunk */ \ |
dsimms@5577 | 3648 | memcpy(result, a->Tag##_at_addr(0), sizeof(ElementType)*len); \ |
dsimms@5577 | 3649 | if (isCopy) { \ |
dsimms@5577 | 3650 | *isCopy = JNI_TRUE; \ |
dsimms@5577 | 3651 | } \ |
dsimms@5577 | 3652 | } \ |
dcubed@3202 | 3653 | } \ |
dcubed@3202 | 3654 | ReturnProbe; \ |
dcubed@3202 | 3655 | return result; \ |
dcubed@3202 | 3656 | JNI_END |
dcubed@3202 | 3657 | |
dcubed@3202 | 3658 | DEFINE_GETSCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3659 | , HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3660 | HOTSPOT_JNI_GETBOOLEANARRAYELEMENTS_RETURN((uintptr_t*)result)) |
dcubed@3202 | 3661 | DEFINE_GETSCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3662 | , HOTSPOT_JNI_GETBYTEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3663 | HOTSPOT_JNI_GETBYTEARRAYELEMENTS_RETURN((char*)result)) |
dcubed@3202 | 3664 | DEFINE_GETSCALARARRAYELEMENTS(T_SHORT, jshort, Short, short |
dcubed@3202 | 3665 | , HOTSPOT_JNI_GETSHORTARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), |
dcubed@3202 | 3666 | HOTSPOT_JNI_GETSHORTARRAYELEMENTS_RETURN((uint16_t*)result)) |
dcubed@3202 | 3667 | DEFINE_GETSCALARARRAYELEMENTS(T_CHAR, jchar, Char, char |
dcubed@3202 | 3668 | , HOTSPOT_JNI_GETCHARARRAYELEMENTS_ENTRY(env, (uint16_t*) array, (uintptr_t *) isCopy), |
dcubed@3202 | 3669 | HOTSPOT_JNI_GETCHARARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3670 | DEFINE_GETSCALARARRAYELEMENTS(T_INT, jint, Int, int |
dcubed@3202 | 3671 | , HOTSPOT_JNI_GETINTARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3672 | HOTSPOT_JNI_GETINTARRAYELEMENTS_RETURN((uint32_t*)result)) |
dcubed@3202 | 3673 | DEFINE_GETSCALARARRAYELEMENTS(T_LONG, jlong, Long, long |
dcubed@3202 | 3674 | , HOTSPOT_JNI_GETLONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3675 | HOTSPOT_JNI_GETLONGARRAYELEMENTS_RETURN(((uintptr_t*)result))) |
dcubed@3202 | 3676 | // Float and double probes don't return value because dtrace doesn't currently support it |
dcubed@3202 | 3677 | DEFINE_GETSCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3678 | , HOTSPOT_JNI_GETFLOATARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3679 | HOTSPOT_JNI_GETFLOATARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3680 | DEFINE_GETSCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3681 | , HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) isCopy), |
dcubed@3202 | 3682 | HOTSPOT_JNI_GETDOUBLEARRAYELEMENTS_RETURN(result)) |
dcubed@3202 | 3683 | #endif /* USDT2 */ |
dcubed@3202 | 3684 | |
dcubed@3202 | 3685 | #ifndef USDT2 |
duke@435 | 3686 | #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag) \ |
duke@435 | 3687 | \ |
duke@435 | 3688 | JNI_QUICK_ENTRY(void, \ |
duke@435 | 3689 | jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ |
duke@435 | 3690 | ElementType *buf, jint mode)) \ |
duke@435 | 3691 | JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ |
duke@435 | 3692 | DTRACE_PROBE4(hotspot_jni, Release##Result##ArrayElements__entry, env, array, buf, mode);\ |
duke@435 | 3693 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3694 | int len = a->length(); \ |
duke@435 | 3695 | if (len != 0) { /* Empty array: nothing to free or copy. */ \ |
duke@435 | 3696 | if ((mode == 0) || (mode == JNI_COMMIT)) { \ |
duke@435 | 3697 | memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ |
duke@435 | 3698 | } \ |
duke@435 | 3699 | if ((mode == 0) || (mode == JNI_ABORT)) { \ |
duke@435 | 3700 | FreeHeap(buf); \ |
duke@435 | 3701 | } \ |
duke@435 | 3702 | } \ |
duke@435 | 3703 | DTRACE_PROBE(hotspot_jni, Release##Result##ArrayElements__return);\ |
duke@435 | 3704 | JNI_END |
duke@435 | 3705 | |
duke@435 | 3706 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3707 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3708 | DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short) |
duke@435 | 3709 | DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char) |
duke@435 | 3710 | DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int) |
duke@435 | 3711 | DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long) |
duke@435 | 3712 | DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float) |
duke@435 | 3713 | DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3714 | |
dcubed@3202 | 3715 | #else /* USDT2 */ |
dcubed@3202 | 3716 | |
dcubed@3202 | 3717 | #define DEFINE_RELEASESCALARARRAYELEMENTS(ElementTag,ElementType,Result,Tag \ |
dcubed@3202 | 3718 | , EntryProbe, ReturnProbe);\ |
dcubed@3202 | 3719 | \ |
dcubed@3202 | 3720 | JNI_QUICK_ENTRY(void, \ |
dcubed@3202 | 3721 | jni_Release##Result##ArrayElements(JNIEnv *env, ElementType##Array array, \ |
dcubed@3202 | 3722 | ElementType *buf, jint mode)) \ |
dcubed@3202 | 3723 | JNIWrapper("Release" XSTR(Result) "ArrayElements"); \ |
dcubed@3202 | 3724 | EntryProbe; \ |
dcubed@3202 | 3725 | typeArrayOop a = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3726 | int len = a->length(); \ |
dcubed@3202 | 3727 | if (len != 0) { /* Empty array: nothing to free or copy. */ \ |
dcubed@3202 | 3728 | if ((mode == 0) || (mode == JNI_COMMIT)) { \ |
dcubed@3202 | 3729 | memcpy(a->Tag##_at_addr(0), buf, sizeof(ElementType)*len); \ |
dcubed@3202 | 3730 | } \ |
dcubed@3202 | 3731 | if ((mode == 0) || (mode == JNI_ABORT)) { \ |
dcubed@3202 | 3732 | FreeHeap(buf); \ |
dcubed@3202 | 3733 | } \ |
dcubed@3202 | 3734 | } \ |
dcubed@3202 | 3735 | ReturnProbe; \ |
dcubed@3202 | 3736 | JNI_END |
dcubed@3202 | 3737 | |
dcubed@3202 | 3738 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3739 | , HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), |
dcubed@3202 | 3740 | HOTSPOT_JNI_RELEASEBOOLEANARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3741 | DEFINE_RELEASESCALARARRAYELEMENTS(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3742 | , HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_ENTRY(env, array, (char *) buf, mode), |
dcubed@3202 | 3743 | HOTSPOT_JNI_RELEASEBYTEARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3744 | DEFINE_RELEASESCALARARRAYELEMENTS(T_SHORT, jshort, Short, short |
dcubed@3202 | 3745 | , HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), |
dcubed@3202 | 3746 | HOTSPOT_JNI_RELEASESHORTARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3747 | DEFINE_RELEASESCALARARRAYELEMENTS(T_CHAR, jchar, Char, char |
dcubed@3202 | 3748 | , HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_ENTRY(env, array, (uint16_t *) buf, mode), |
dcubed@3202 | 3749 | HOTSPOT_JNI_RELEASECHARARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3750 | DEFINE_RELEASESCALARARRAYELEMENTS(T_INT, jint, Int, int |
dcubed@3202 | 3751 | , HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_ENTRY(env, array, (uint32_t *) buf, mode), |
dcubed@3202 | 3752 | HOTSPOT_JNI_RELEASEINTARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3753 | DEFINE_RELEASESCALARARRAYELEMENTS(T_LONG, jlong, Long, long |
dcubed@3202 | 3754 | , HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_ENTRY(env, array, (uintptr_t *) buf, mode), |
dcubed@3202 | 3755 | HOTSPOT_JNI_RELEASELONGARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3756 | DEFINE_RELEASESCALARARRAYELEMENTS(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3757 | , HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_ENTRY(env, array, (float *) buf, mode), |
dcubed@3202 | 3758 | HOTSPOT_JNI_RELEASEFLOATARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3759 | DEFINE_RELEASESCALARARRAYELEMENTS(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3760 | , HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_ENTRY(env, array, (double *) buf, mode), |
dcubed@3202 | 3761 | HOTSPOT_JNI_RELEASEDOUBLEARRAYELEMENTS_RETURN()) |
dcubed@3202 | 3762 | #endif /* USDT2 */ |
dcubed@3202 | 3763 | |
dcubed@3202 | 3764 | #ifndef USDT2 |
duke@435 | 3765 | #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3766 | DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion);\ |
duke@435 | 3767 | \ |
duke@435 | 3768 | JNI_ENTRY(void, \ |
duke@435 | 3769 | jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
duke@435 | 3770 | jsize len, ElementType *buf)) \ |
duke@435 | 3771 | JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ |
duke@435 | 3772 | DTRACE_PROBE5(hotspot_jni, Get##Result##ArrayRegion__entry, env, array, start, len, buf);\ |
duke@435 | 3773 | DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ |
duke@435 | 3774 | typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3775 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ |
duke@435 | 3776 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
duke@435 | 3777 | } else { \ |
duke@435 | 3778 | if (len > 0) { \ |
coleenp@4142 | 3779 | int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \ |
duke@435 | 3780 | memcpy((u_char*) buf, \ |
duke@435 | 3781 | (u_char*) src->Tag##_at_addr(start), \ |
duke@435 | 3782 | len << sc); \ |
duke@435 | 3783 | } \ |
duke@435 | 3784 | } \ |
duke@435 | 3785 | JNI_END |
duke@435 | 3786 | |
duke@435 | 3787 | DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool) |
duke@435 | 3788 | DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3789 | DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short) |
duke@435 | 3790 | DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char) |
duke@435 | 3791 | DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int) |
duke@435 | 3792 | DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long) |
duke@435 | 3793 | DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) |
duke@435 | 3794 | DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3795 | |
dcubed@3202 | 3796 | #else /* USDT2 */ |
dcubed@3202 | 3797 | |
dcubed@3202 | 3798 | #define DEFINE_GETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3799 | , EntryProbe, ReturnProbe); \ |
dcubed@3202 | 3800 | DT_VOID_RETURN_MARK_DECL(Get##Result##ArrayRegion \ |
dcubed@3202 | 3801 | , ReturnProbe); \ |
dcubed@3202 | 3802 | \ |
dcubed@3202 | 3803 | JNI_ENTRY(void, \ |
dcubed@3202 | 3804 | jni_Get##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
dcubed@3202 | 3805 | jsize len, ElementType *buf)) \ |
dcubed@3202 | 3806 | JNIWrapper("Get" XSTR(Result) "ArrayRegion"); \ |
dcubed@3202 | 3807 | EntryProbe; \ |
dcubed@3202 | 3808 | DT_VOID_RETURN_MARK(Get##Result##ArrayRegion); \ |
dcubed@3202 | 3809 | typeArrayOop src = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3810 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)src->length())) { \ |
dcubed@3202 | 3811 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
dcubed@3202 | 3812 | } else { \ |
dcubed@3202 | 3813 | if (len > 0) { \ |
coleenp@4142 | 3814 | int sc = TypeArrayKlass::cast(src->klass())->log2_element_size(); \ |
dcubed@3202 | 3815 | memcpy((u_char*) buf, \ |
dcubed@3202 | 3816 | (u_char*) src->Tag##_at_addr(start), \ |
dcubed@3202 | 3817 | len << sc); \ |
dcubed@3202 | 3818 | } \ |
dcubed@3202 | 3819 | } \ |
dcubed@3202 | 3820 | JNI_END |
dcubed@3202 | 3821 | |
dcubed@3202 | 3822 | DEFINE_GETSCALARARRAYREGION(T_BOOLEAN, jboolean,Boolean, bool |
dcubed@3202 | 3823 | , HOTSPOT_JNI_GETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3824 | HOTSPOT_JNI_GETBOOLEANARRAYREGION_RETURN()); |
dcubed@3202 | 3825 | DEFINE_GETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3826 | , HOTSPOT_JNI_GETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), |
dcubed@3202 | 3827 | HOTSPOT_JNI_GETBYTEARRAYREGION_RETURN()); |
dcubed@3202 | 3828 | DEFINE_GETSCALARARRAYREGION(T_SHORT, jshort, Short, short |
dcubed@3202 | 3829 | , HOTSPOT_JNI_GETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3830 | HOTSPOT_JNI_GETSHORTARRAYREGION_RETURN()); |
dcubed@3202 | 3831 | DEFINE_GETSCALARARRAYREGION(T_CHAR, jchar, Char, char |
dcubed@3202 | 3832 | , HOTSPOT_JNI_GETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t*) buf), |
dcubed@3202 | 3833 | HOTSPOT_JNI_GETCHARARRAYREGION_RETURN()); |
dcubed@3202 | 3834 | DEFINE_GETSCALARARRAYREGION(T_INT, jint, Int, int |
dcubed@3202 | 3835 | , HOTSPOT_JNI_GETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t*) buf), |
dcubed@3202 | 3836 | HOTSPOT_JNI_GETINTARRAYREGION_RETURN()); |
dcubed@3202 | 3837 | DEFINE_GETSCALARARRAYREGION(T_LONG, jlong, Long, long |
dcubed@3202 | 3838 | , HOTSPOT_JNI_GETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3839 | HOTSPOT_JNI_GETLONGARRAYREGION_RETURN()); |
dcubed@3202 | 3840 | DEFINE_GETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3841 | , HOTSPOT_JNI_GETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), |
dcubed@3202 | 3842 | HOTSPOT_JNI_GETFLOATARRAYREGION_RETURN()); |
dcubed@3202 | 3843 | DEFINE_GETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3844 | , HOTSPOT_JNI_GETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), |
dcubed@3202 | 3845 | HOTSPOT_JNI_GETDOUBLEARRAYREGION_RETURN()); |
dcubed@3202 | 3846 | #endif /* USDT2 */ |
dcubed@3202 | 3847 | |
dcubed@3202 | 3848 | #ifndef USDT2 |
duke@435 | 3849 | #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag) \ |
duke@435 | 3850 | DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion);\ |
duke@435 | 3851 | \ |
duke@435 | 3852 | JNI_ENTRY(void, \ |
duke@435 | 3853 | jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
duke@435 | 3854 | jsize len, const ElementType *buf)) \ |
duke@435 | 3855 | JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ |
duke@435 | 3856 | DTRACE_PROBE5(hotspot_jni, Set##Result##ArrayRegion__entry, env, array, start, len, buf);\ |
duke@435 | 3857 | DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ |
duke@435 | 3858 | typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
duke@435 | 3859 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ |
duke@435 | 3860 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
duke@435 | 3861 | } else { \ |
duke@435 | 3862 | if (len > 0) { \ |
coleenp@4142 | 3863 | int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \ |
duke@435 | 3864 | memcpy((u_char*) dst->Tag##_at_addr(start), \ |
duke@435 | 3865 | (u_char*) buf, \ |
duke@435 | 3866 | len << sc); \ |
duke@435 | 3867 | } \ |
duke@435 | 3868 | } \ |
duke@435 | 3869 | JNI_END |
duke@435 | 3870 | |
duke@435 | 3871 | DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool) |
duke@435 | 3872 | DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte) |
duke@435 | 3873 | DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short) |
duke@435 | 3874 | DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char) |
duke@435 | 3875 | DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int) |
duke@435 | 3876 | DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long) |
duke@435 | 3877 | DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float) |
duke@435 | 3878 | DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double) |
duke@435 | 3879 | |
dcubed@3202 | 3880 | #else /* USDT2 */ |
dcubed@3202 | 3881 | |
dcubed@3202 | 3882 | #define DEFINE_SETSCALARARRAYREGION(ElementTag,ElementType,Result, Tag \ |
dcubed@3202 | 3883 | , EntryProbe, ReturnProbe); \ |
dcubed@3202 | 3884 | DT_VOID_RETURN_MARK_DECL(Set##Result##ArrayRegion \ |
dcubed@3202 | 3885 | ,ReturnProbe); \ |
dcubed@3202 | 3886 | \ |
dcubed@3202 | 3887 | JNI_ENTRY(void, \ |
dcubed@3202 | 3888 | jni_Set##Result##ArrayRegion(JNIEnv *env, ElementType##Array array, jsize start, \ |
dcubed@3202 | 3889 | jsize len, const ElementType *buf)) \ |
dcubed@3202 | 3890 | JNIWrapper("Set" XSTR(Result) "ArrayRegion"); \ |
dcubed@3202 | 3891 | EntryProbe; \ |
dcubed@3202 | 3892 | DT_VOID_RETURN_MARK(Set##Result##ArrayRegion); \ |
dcubed@3202 | 3893 | typeArrayOop dst = typeArrayOop(JNIHandles::resolve_non_null(array)); \ |
dcubed@3202 | 3894 | if (start < 0 || len < 0 || ((unsigned int)start + (unsigned int)len > (unsigned int)dst->length())) { \ |
dcubed@3202 | 3895 | THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException()); \ |
dcubed@3202 | 3896 | } else { \ |
dcubed@3202 | 3897 | if (len > 0) { \ |
coleenp@4142 | 3898 | int sc = TypeArrayKlass::cast(dst->klass())->log2_element_size(); \ |
dcubed@3202 | 3899 | memcpy((u_char*) dst->Tag##_at_addr(start), \ |
dcubed@3202 | 3900 | (u_char*) buf, \ |
dcubed@3202 | 3901 | len << sc); \ |
dcubed@3202 | 3902 | } \ |
dcubed@3202 | 3903 | } \ |
dcubed@3202 | 3904 | JNI_END |
dcubed@3202 | 3905 | |
dcubed@3202 | 3906 | DEFINE_SETSCALARARRAYREGION(T_BOOLEAN, jboolean, Boolean, bool |
dcubed@3202 | 3907 | , HOTSPOT_JNI_SETBOOLEANARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *)buf), |
dcubed@3202 | 3908 | HOTSPOT_JNI_SETBOOLEANARRAYREGION_RETURN()) |
dcubed@3202 | 3909 | DEFINE_SETSCALARARRAYREGION(T_BYTE, jbyte, Byte, byte |
dcubed@3202 | 3910 | , HOTSPOT_JNI_SETBYTEARRAYREGION_ENTRY(env, array, start, len, (char *) buf), |
dcubed@3202 | 3911 | HOTSPOT_JNI_SETBYTEARRAYREGION_RETURN()) |
dcubed@3202 | 3912 | DEFINE_SETSCALARARRAYREGION(T_SHORT, jshort, Short, short |
dcubed@3202 | 3913 | , HOTSPOT_JNI_SETSHORTARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3914 | HOTSPOT_JNI_SETSHORTARRAYREGION_RETURN()) |
dcubed@3202 | 3915 | DEFINE_SETSCALARARRAYREGION(T_CHAR, jchar, Char, char |
dcubed@3202 | 3916 | , HOTSPOT_JNI_SETCHARARRAYREGION_ENTRY(env, array, start, len, (uint16_t *) buf), |
dcubed@3202 | 3917 | HOTSPOT_JNI_SETCHARARRAYREGION_RETURN()) |
dcubed@3202 | 3918 | DEFINE_SETSCALARARRAYREGION(T_INT, jint, Int, int |
dcubed@3202 | 3919 | , HOTSPOT_JNI_SETINTARRAYREGION_ENTRY(env, array, start, len, (uint32_t *) buf), |
dcubed@3202 | 3920 | HOTSPOT_JNI_SETINTARRAYREGION_RETURN()) |
dcubed@3202 | 3921 | DEFINE_SETSCALARARRAYREGION(T_LONG, jlong, Long, long |
dcubed@3202 | 3922 | , HOTSPOT_JNI_SETLONGARRAYREGION_ENTRY(env, array, start, len, (uintptr_t *) buf), |
dcubed@3202 | 3923 | HOTSPOT_JNI_SETLONGARRAYREGION_RETURN()) |
dcubed@3202 | 3924 | DEFINE_SETSCALARARRAYREGION(T_FLOAT, jfloat, Float, float |
dcubed@3202 | 3925 | , HOTSPOT_JNI_SETFLOATARRAYREGION_ENTRY(env, array, start, len, (float *) buf), |
dcubed@3202 | 3926 | HOTSPOT_JNI_SETFLOATARRAYREGION_RETURN()) |
dcubed@3202 | 3927 | DEFINE_SETSCALARARRAYREGION(T_DOUBLE, jdouble, Double, double |
dcubed@3202 | 3928 | , HOTSPOT_JNI_SETDOUBLEARRAYREGION_ENTRY(env, array, start, len, (double *) buf), |
dcubed@3202 | 3929 | HOTSPOT_JNI_SETDOUBLEARRAYREGION_RETURN()) |
dcubed@3202 | 3930 | #endif /* USDT2 */ |
dcubed@3202 | 3931 | |
duke@435 | 3932 | |
duke@435 | 3933 | // |
duke@435 | 3934 | // Interception of natives |
duke@435 | 3935 | // |
duke@435 | 3936 | |
duke@435 | 3937 | // The RegisterNatives call being attempted tried to register with a method that |
duke@435 | 3938 | // is not native. Ask JVM TI what prefixes have been specified. Then check |
duke@435 | 3939 | // to see if the native method is now wrapped with the prefixes. See the |
duke@435 | 3940 | // SetNativeMethodPrefix(es) functions in the JVM TI Spec for details. |
coleenp@4037 | 3941 | static Method* find_prefixed_native(KlassHandle k, |
coleenp@2497 | 3942 | Symbol* name, Symbol* signature, TRAPS) { |
jprovino@4165 | 3943 | #if INCLUDE_JVMTI |
duke@435 | 3944 | ResourceMark rm(THREAD); |
coleenp@4037 | 3945 | Method* method; |
duke@435 | 3946 | int name_len = name->utf8_length(); |
duke@435 | 3947 | char* name_str = name->as_utf8(); |
duke@435 | 3948 | int prefix_count; |
duke@435 | 3949 | char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); |
duke@435 | 3950 | for (int i = 0; i < prefix_count; i++) { |
duke@435 | 3951 | char* prefix = prefixes[i]; |
duke@435 | 3952 | int prefix_len = (int)strlen(prefix); |
duke@435 | 3953 | |
duke@435 | 3954 | // try adding this prefix to the method name and see if it matches another method name |
duke@435 | 3955 | int trial_len = name_len + prefix_len; |
duke@435 | 3956 | char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1); |
duke@435 | 3957 | strcpy(trial_name_str, prefix); |
duke@435 | 3958 | strcat(trial_name_str, name_str); |
coleenp@2497 | 3959 | TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len); |
coleenp@2497 | 3960 | if (trial_name == NULL) { |
duke@435 | 3961 | continue; // no such symbol, so this prefix wasn't used, try the next prefix |
duke@435 | 3962 | } |
hseigel@4278 | 3963 | method = k()->lookup_method(trial_name, signature); |
duke@435 | 3964 | if (method == NULL) { |
duke@435 | 3965 | continue; // signature doesn't match, try the next prefix |
duke@435 | 3966 | } |
duke@435 | 3967 | if (method->is_native()) { |
duke@435 | 3968 | method->set_is_prefixed_native(); |
duke@435 | 3969 | return method; // wahoo, we found a prefixed version of the method, return it |
duke@435 | 3970 | } |
duke@435 | 3971 | // found as non-native, so prefix is good, add it, probably just need more prefixes |
duke@435 | 3972 | name_len = trial_len; |
duke@435 | 3973 | name_str = trial_name_str; |
duke@435 | 3974 | } |
jprovino@4165 | 3975 | #endif // INCLUDE_JVMTI |
duke@435 | 3976 | return NULL; // not found |
duke@435 | 3977 | } |
duke@435 | 3978 | |
coleenp@2497 | 3979 | static bool register_native(KlassHandle k, Symbol* name, Symbol* signature, address entry, TRAPS) { |
hseigel@4278 | 3980 | Method* method = k()->lookup_method(name, signature); |
duke@435 | 3981 | if (method == NULL) { |
duke@435 | 3982 | ResourceMark rm; |
duke@435 | 3983 | stringStream st; |
duke@435 | 3984 | st.print("Method %s name or signature does not match", |
hseigel@4278 | 3985 | Method::name_and_sig_as_C_string(k(), name, signature)); |
duke@435 | 3986 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
duke@435 | 3987 | } |
duke@435 | 3988 | if (!method->is_native()) { |
duke@435 | 3989 | // trying to register to a non-native method, see if a JVM TI agent has added prefix(es) |
duke@435 | 3990 | method = find_prefixed_native(k, name, signature, THREAD); |
duke@435 | 3991 | if (method == NULL) { |
duke@435 | 3992 | ResourceMark rm; |
duke@435 | 3993 | stringStream st; |
duke@435 | 3994 | st.print("Method %s is not declared as native", |
hseigel@4278 | 3995 | Method::name_and_sig_as_C_string(k(), name, signature)); |
duke@435 | 3996 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), false); |
duke@435 | 3997 | } |
duke@435 | 3998 | } |
duke@435 | 3999 | |
duke@435 | 4000 | if (entry != NULL) { |
duke@435 | 4001 | method->set_native_function(entry, |
coleenp@4037 | 4002 | Method::native_bind_event_is_interesting); |
duke@435 | 4003 | } else { |
duke@435 | 4004 | method->clear_native_function(); |
duke@435 | 4005 | } |
duke@435 | 4006 | if (PrintJNIResolving) { |
duke@435 | 4007 | ResourceMark rm(THREAD); |
duke@435 | 4008 | tty->print_cr("[Registering JNI native method %s.%s]", |
coleenp@4251 | 4009 | method->method_holder()->external_name(), |
duke@435 | 4010 | method->name()->as_C_string()); |
duke@435 | 4011 | } |
duke@435 | 4012 | return true; |
duke@435 | 4013 | } |
duke@435 | 4014 | |
dcubed@3202 | 4015 | #ifndef USDT2 |
duke@435 | 4016 | DT_RETURN_MARK_DECL(RegisterNatives, jint); |
dcubed@3202 | 4017 | #else /* USDT2 */ |
dcubed@3202 | 4018 | DT_RETURN_MARK_DECL(RegisterNatives, jint |
dcubed@3202 | 4019 | , HOTSPOT_JNI_REGISTERNATIVES_RETURN(_ret_ref)); |
dcubed@3202 | 4020 | #endif /* USDT2 */ |
duke@435 | 4021 | |
duke@435 | 4022 | JNI_ENTRY(jint, jni_RegisterNatives(JNIEnv *env, jclass clazz, |
duke@435 | 4023 | const JNINativeMethod *methods, |
duke@435 | 4024 | jint nMethods)) |
duke@435 | 4025 | JNIWrapper("RegisterNatives"); |
dcubed@3202 | 4026 | #ifndef USDT2 |
duke@435 | 4027 | DTRACE_PROBE4(hotspot_jni, RegisterNatives__entry, env, clazz, methods, nMethods); |
dcubed@3202 | 4028 | #else /* USDT2 */ |
dcubed@3202 | 4029 | HOTSPOT_JNI_REGISTERNATIVES_ENTRY( |
dcubed@3202 | 4030 | env, clazz, (void *) methods, nMethods); |
dcubed@3202 | 4031 | #endif /* USDT2 */ |
duke@435 | 4032 | jint ret = 0; |
duke@435 | 4033 | DT_RETURN_MARK(RegisterNatives, jint, (const jint&)ret); |
duke@435 | 4034 | |
coleenp@4037 | 4035 | KlassHandle h_k(thread, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); |
duke@435 | 4036 | |
duke@435 | 4037 | for (int index = 0; index < nMethods; index++) { |
duke@435 | 4038 | const char* meth_name = methods[index].name; |
duke@435 | 4039 | const char* meth_sig = methods[index].signature; |
duke@435 | 4040 | int meth_name_len = (int)strlen(meth_name); |
duke@435 | 4041 | |
duke@435 | 4042 | // The class should have been loaded (we have an instance of the class |
duke@435 | 4043 | // passed in) so the method and signature should already be in the symbol |
duke@435 | 4044 | // table. If they're not there, the method doesn't exist. |
coleenp@2497 | 4045 | TempNewSymbol name = SymbolTable::probe(meth_name, meth_name_len); |
coleenp@2497 | 4046 | TempNewSymbol signature = SymbolTable::probe(meth_sig, (int)strlen(meth_sig)); |
coleenp@2497 | 4047 | |
coleenp@2497 | 4048 | if (name == NULL || signature == NULL) { |
duke@435 | 4049 | ResourceMark rm; |
duke@435 | 4050 | stringStream st; |
hseigel@4278 | 4051 | st.print("Method %s.%s%s not found", h_k()->external_name(), meth_name, meth_sig); |
duke@435 | 4052 | // Must return negative value on failure |
duke@435 | 4053 | THROW_MSG_(vmSymbols::java_lang_NoSuchMethodError(), st.as_string(), -1); |
duke@435 | 4054 | } |
duke@435 | 4055 | |
duke@435 | 4056 | bool res = register_native(h_k, name, signature, |
duke@435 | 4057 | (address) methods[index].fnPtr, THREAD); |
duke@435 | 4058 | if (!res) { |
duke@435 | 4059 | ret = -1; |
duke@435 | 4060 | break; |
duke@435 | 4061 | } |
duke@435 | 4062 | } |
duke@435 | 4063 | return ret; |
duke@435 | 4064 | JNI_END |
duke@435 | 4065 | |
duke@435 | 4066 | |
duke@435 | 4067 | JNI_ENTRY(jint, jni_UnregisterNatives(JNIEnv *env, jclass clazz)) |
duke@435 | 4068 | JNIWrapper("UnregisterNatives"); |
dcubed@3202 | 4069 | #ifndef USDT2 |
duke@435 | 4070 | DTRACE_PROBE2(hotspot_jni, UnregisterNatives__entry, env, clazz); |
dcubed@3202 | 4071 | #else /* USDT2 */ |
dcubed@3202 | 4072 | HOTSPOT_JNI_UNREGISTERNATIVES_ENTRY( |
dcubed@3202 | 4073 | env, clazz); |
dcubed@3202 | 4074 | #endif /* USDT2 */ |
coleenp@4037 | 4075 | Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)); |
duke@435 | 4076 | //%note jni_2 |
hseigel@4278 | 4077 | if (k->oop_is_instance()) { |
coleenp@4037 | 4078 | for (int index = 0; index < InstanceKlass::cast(k)->methods()->length(); index++) { |
coleenp@4037 | 4079 | Method* m = InstanceKlass::cast(k)->methods()->at(index); |
duke@435 | 4080 | if (m->is_native()) { |
duke@435 | 4081 | m->clear_native_function(); |
duke@435 | 4082 | m->set_signature_handler(NULL); |
duke@435 | 4083 | } |
duke@435 | 4084 | } |
duke@435 | 4085 | } |
dcubed@3202 | 4086 | #ifndef USDT2 |
duke@435 | 4087 | DTRACE_PROBE1(hotspot_jni, UnregisterNatives__return, 0); |
dcubed@3202 | 4088 | #else /* USDT2 */ |
dcubed@3202 | 4089 | HOTSPOT_JNI_UNREGISTERNATIVES_RETURN( |
dcubed@3202 | 4090 | 0); |
dcubed@3202 | 4091 | #endif /* USDT2 */ |
duke@435 | 4092 | return 0; |
duke@435 | 4093 | JNI_END |
duke@435 | 4094 | |
duke@435 | 4095 | // |
duke@435 | 4096 | // Monitor functions |
duke@435 | 4097 | // |
duke@435 | 4098 | |
dcubed@3202 | 4099 | #ifndef USDT2 |
duke@435 | 4100 | DT_RETURN_MARK_DECL(MonitorEnter, jint); |
dcubed@3202 | 4101 | #else /* USDT2 */ |
dcubed@3202 | 4102 | DT_RETURN_MARK_DECL(MonitorEnter, jint |
dcubed@3202 | 4103 | , HOTSPOT_JNI_MONITORENTER_RETURN(_ret_ref)); |
dcubed@3202 | 4104 | #endif /* USDT2 */ |
duke@435 | 4105 | |
duke@435 | 4106 | JNI_ENTRY(jint, jni_MonitorEnter(JNIEnv *env, jobject jobj)) |
dcubed@3202 | 4107 | #ifndef USDT2 |
duke@435 | 4108 | DTRACE_PROBE2(hotspot_jni, MonitorEnter__entry, env, jobj); |
dcubed@3202 | 4109 | #else /* USDT2 */ |
dcubed@3202 | 4110 | HOTSPOT_JNI_MONITORENTER_ENTRY( |
dcubed@3202 | 4111 | env, jobj); |
dcubed@3202 | 4112 | #endif /* USDT2 */ |
duke@435 | 4113 | jint ret = JNI_ERR; |
duke@435 | 4114 | DT_RETURN_MARK(MonitorEnter, jint, (const jint&)ret); |
duke@435 | 4115 | |
duke@435 | 4116 | // If the object is null, we can't do anything with it |
duke@435 | 4117 | if (jobj == NULL) { |
duke@435 | 4118 | THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); |
duke@435 | 4119 | } |
duke@435 | 4120 | |
duke@435 | 4121 | Handle obj(thread, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 4122 | ObjectSynchronizer::jni_enter(obj, CHECK_(JNI_ERR)); |
duke@435 | 4123 | ret = JNI_OK; |
duke@435 | 4124 | return ret; |
duke@435 | 4125 | JNI_END |
duke@435 | 4126 | |
dcubed@3202 | 4127 | #ifndef USDT2 |
duke@435 | 4128 | DT_RETURN_MARK_DECL(MonitorExit, jint); |
dcubed@3202 | 4129 | #else /* USDT2 */ |
dcubed@3202 | 4130 | DT_RETURN_MARK_DECL(MonitorExit, jint |
dcubed@3202 | 4131 | , HOTSPOT_JNI_MONITOREXIT_RETURN(_ret_ref)); |
dcubed@3202 | 4132 | #endif /* USDT2 */ |
duke@435 | 4133 | |
duke@435 | 4134 | JNI_ENTRY(jint, jni_MonitorExit(JNIEnv *env, jobject jobj)) |
dcubed@3202 | 4135 | #ifndef USDT2 |
duke@435 | 4136 | DTRACE_PROBE2(hotspot_jni, MonitorExit__entry, env, jobj); |
dcubed@3202 | 4137 | #else /* USDT2 */ |
dcubed@3202 | 4138 | HOTSPOT_JNI_MONITOREXIT_ENTRY( |
dcubed@3202 | 4139 | env, jobj); |
dcubed@3202 | 4140 | #endif /* USDT2 */ |
duke@435 | 4141 | jint ret = JNI_ERR; |
duke@435 | 4142 | DT_RETURN_MARK(MonitorExit, jint, (const jint&)ret); |
duke@435 | 4143 | |
duke@435 | 4144 | // Don't do anything with a null object |
duke@435 | 4145 | if (jobj == NULL) { |
duke@435 | 4146 | THROW_(vmSymbols::java_lang_NullPointerException(), JNI_ERR); |
duke@435 | 4147 | } |
duke@435 | 4148 | |
duke@435 | 4149 | Handle obj(THREAD, JNIHandles::resolve_non_null(jobj)); |
duke@435 | 4150 | ObjectSynchronizer::jni_exit(obj(), CHECK_(JNI_ERR)); |
duke@435 | 4151 | |
duke@435 | 4152 | ret = JNI_OK; |
duke@435 | 4153 | return ret; |
duke@435 | 4154 | JNI_END |
duke@435 | 4155 | |
duke@435 | 4156 | // |
duke@435 | 4157 | // Extensions |
duke@435 | 4158 | // |
duke@435 | 4159 | |
dcubed@3202 | 4160 | #ifndef USDT2 |
duke@435 | 4161 | DT_VOID_RETURN_MARK_DECL(GetStringRegion); |
dcubed@3202 | 4162 | #else /* USDT2 */ |
dcubed@3202 | 4163 | DT_VOID_RETURN_MARK_DECL(GetStringRegion |
dcubed@3202 | 4164 | , HOTSPOT_JNI_GETSTRINGREGION_RETURN()); |
dcubed@3202 | 4165 | #endif /* USDT2 */ |
duke@435 | 4166 | |
duke@435 | 4167 | JNI_ENTRY(void, jni_GetStringRegion(JNIEnv *env, jstring string, jsize start, jsize len, jchar *buf)) |
duke@435 | 4168 | JNIWrapper("GetStringRegion"); |
dcubed@3202 | 4169 | #ifndef USDT2 |
duke@435 | 4170 | DTRACE_PROBE5(hotspot_jni, GetStringRegion__entry, env, string, start, len, buf); |
dcubed@3202 | 4171 | #else /* USDT2 */ |
dcubed@3202 | 4172 | HOTSPOT_JNI_GETSTRINGREGION_ENTRY( |
dcubed@3202 | 4173 | env, string, start, len, buf); |
dcubed@3202 | 4174 | #endif /* USDT2 */ |
duke@435 | 4175 | DT_VOID_RETURN_MARK(GetStringRegion); |
duke@435 | 4176 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4177 | int s_len = java_lang_String::length(s); |
duke@435 | 4178 | if (start < 0 || len < 0 || start + len > s_len) { |
duke@435 | 4179 | THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); |
duke@435 | 4180 | } else { |
duke@435 | 4181 | if (len > 0) { |
duke@435 | 4182 | int s_offset = java_lang_String::offset(s); |
duke@435 | 4183 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 4184 | memcpy(buf, s_value->char_at_addr(s_offset+start), sizeof(jchar)*len); |
duke@435 | 4185 | } |
duke@435 | 4186 | } |
duke@435 | 4187 | JNI_END |
duke@435 | 4188 | |
dcubed@3202 | 4189 | #ifndef USDT2 |
duke@435 | 4190 | DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion); |
dcubed@3202 | 4191 | #else /* USDT2 */ |
dcubed@3202 | 4192 | DT_VOID_RETURN_MARK_DECL(GetStringUTFRegion |
dcubed@3202 | 4193 | , HOTSPOT_JNI_GETSTRINGUTFREGION_RETURN()); |
dcubed@3202 | 4194 | #endif /* USDT2 */ |
duke@435 | 4195 | |
duke@435 | 4196 | JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string, jsize start, jsize len, char *buf)) |
duke@435 | 4197 | JNIWrapper("GetStringUTFRegion"); |
dcubed@3202 | 4198 | #ifndef USDT2 |
duke@435 | 4199 | DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string, start, len, buf); |
dcubed@3202 | 4200 | #else /* USDT2 */ |
dcubed@3202 | 4201 | HOTSPOT_JNI_GETSTRINGUTFREGION_ENTRY( |
dcubed@3202 | 4202 | env, string, start, len, buf); |
dcubed@3202 | 4203 | #endif /* USDT2 */ |
duke@435 | 4204 | DT_VOID_RETURN_MARK(GetStringUTFRegion); |
duke@435 | 4205 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4206 | int s_len = java_lang_String::length(s); |
duke@435 | 4207 | if (start < 0 || len < 0 || start + len > s_len) { |
duke@435 | 4208 | THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException()); |
duke@435 | 4209 | } else { |
duke@435 | 4210 | //%note jni_7 |
duke@435 | 4211 | if (len > 0) { |
duke@435 | 4212 | ResourceMark rm(THREAD); |
duke@435 | 4213 | char *utf_region = java_lang_String::as_utf8_string(s, start, len); |
duke@435 | 4214 | int utf_len = (int)strlen(utf_region); |
duke@435 | 4215 | memcpy(buf, utf_region, utf_len); |
duke@435 | 4216 | buf[utf_len] = 0; |
duke@435 | 4217 | } else { |
duke@435 | 4218 | // JDK null-terminates the buffer even in len is zero |
duke@435 | 4219 | if (buf != NULL) { |
duke@435 | 4220 | buf[0] = 0; |
duke@435 | 4221 | } |
duke@435 | 4222 | } |
duke@435 | 4223 | } |
duke@435 | 4224 | JNI_END |
duke@435 | 4225 | |
duke@435 | 4226 | |
duke@435 | 4227 | JNI_ENTRY(void*, jni_GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)) |
duke@435 | 4228 | JNIWrapper("GetPrimitiveArrayCritical"); |
dcubed@3202 | 4229 | #ifndef USDT2 |
duke@435 | 4230 | DTRACE_PROBE3(hotspot_jni, GetPrimitiveArrayCritical__entry, env, array, isCopy); |
dcubed@3202 | 4231 | #else /* USDT2 */ |
dcubed@3202 | 4232 | HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_ENTRY( |
dcubed@3202 | 4233 | env, array, (uintptr_t *) isCopy); |
dcubed@3202 | 4234 | #endif /* USDT2 */ |
duke@435 | 4235 | GC_locker::lock_critical(thread); |
duke@435 | 4236 | if (isCopy != NULL) { |
duke@435 | 4237 | *isCopy = JNI_FALSE; |
duke@435 | 4238 | } |
duke@435 | 4239 | oop a = JNIHandles::resolve_non_null(array); |
duke@435 | 4240 | assert(a->is_array(), "just checking"); |
duke@435 | 4241 | BasicType type; |
duke@435 | 4242 | if (a->is_objArray()) { |
duke@435 | 4243 | type = T_OBJECT; |
duke@435 | 4244 | } else { |
coleenp@4142 | 4245 | type = TypeArrayKlass::cast(a->klass())->element_type(); |
duke@435 | 4246 | } |
duke@435 | 4247 | void* ret = arrayOop(a)->base(type); |
dcubed@3202 | 4248 | #ifndef USDT2 |
duke@435 | 4249 | DTRACE_PROBE1(hotspot_jni, GetPrimitiveArrayCritical__return, ret); |
dcubed@3202 | 4250 | #else /* USDT2 */ |
dcubed@3202 | 4251 | HOTSPOT_JNI_GETPRIMITIVEARRAYCRITICAL_RETURN( |
dcubed@3202 | 4252 | ret); |
dcubed@3202 | 4253 | #endif /* USDT2 */ |
duke@435 | 4254 | return ret; |
duke@435 | 4255 | JNI_END |
duke@435 | 4256 | |
duke@435 | 4257 | |
duke@435 | 4258 | JNI_ENTRY(void, jni_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray, jint mode)) |
duke@435 | 4259 | JNIWrapper("ReleasePrimitiveArrayCritical"); |
dcubed@3202 | 4260 | #ifndef USDT2 |
duke@435 | 4261 | DTRACE_PROBE4(hotspot_jni, ReleasePrimitiveArrayCritical__entry, env, array, carray, mode); |
dcubed@3202 | 4262 | #else /* USDT2 */ |
dcubed@3202 | 4263 | HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_ENTRY( |
dcubed@3202 | 4264 | env, array, carray, mode); |
dcubed@3202 | 4265 | #endif /* USDT2 */ |
duke@435 | 4266 | // The array, carray and mode arguments are ignored |
duke@435 | 4267 | GC_locker::unlock_critical(thread); |
dcubed@3202 | 4268 | #ifndef USDT2 |
duke@435 | 4269 | DTRACE_PROBE(hotspot_jni, ReleasePrimitiveArrayCritical__return); |
dcubed@3202 | 4270 | #else /* USDT2 */ |
dcubed@3202 | 4271 | HOTSPOT_JNI_RELEASEPRIMITIVEARRAYCRITICAL_RETURN( |
dcubed@3202 | 4272 | ); |
dcubed@3202 | 4273 | #endif /* USDT2 */ |
duke@435 | 4274 | JNI_END |
duke@435 | 4275 | |
duke@435 | 4276 | |
duke@435 | 4277 | JNI_ENTRY(const jchar*, jni_GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)) |
duke@435 | 4278 | JNIWrapper("GetStringCritical"); |
dcubed@3202 | 4279 | #ifndef USDT2 |
duke@435 | 4280 | DTRACE_PROBE3(hotspot_jni, GetStringCritical__entry, env, string, isCopy); |
dcubed@3202 | 4281 | #else /* USDT2 */ |
dcubed@3202 | 4282 | HOTSPOT_JNI_GETSTRINGCRITICAL_ENTRY( |
dcubed@3202 | 4283 | env, string, (uintptr_t *) isCopy); |
dcubed@3202 | 4284 | #endif /* USDT2 */ |
duke@435 | 4285 | GC_locker::lock_critical(thread); |
duke@435 | 4286 | if (isCopy != NULL) { |
duke@435 | 4287 | *isCopy = JNI_FALSE; |
duke@435 | 4288 | } |
duke@435 | 4289 | oop s = JNIHandles::resolve_non_null(string); |
duke@435 | 4290 | int s_len = java_lang_String::length(s); |
duke@435 | 4291 | typeArrayOop s_value = java_lang_String::value(s); |
duke@435 | 4292 | int s_offset = java_lang_String::offset(s); |
duke@435 | 4293 | const jchar* ret; |
duke@435 | 4294 | if (s_len > 0) { |
duke@435 | 4295 | ret = s_value->char_at_addr(s_offset); |
duke@435 | 4296 | } else { |
duke@435 | 4297 | ret = (jchar*) s_value->base(T_CHAR); |
duke@435 | 4298 | } |
dcubed@3202 | 4299 | #ifndef USDT2 |
duke@435 | 4300 | DTRACE_PROBE1(hotspot_jni, GetStringCritical__return, ret); |
dcubed@3202 | 4301 | #else /* USDT2 */ |
dcubed@3202 | 4302 | HOTSPOT_JNI_GETSTRINGCRITICAL_RETURN( |
dcubed@3202 | 4303 | (uint16_t *) ret); |
dcubed@3202 | 4304 | #endif /* USDT2 */ |
duke@435 | 4305 | return ret; |
duke@435 | 4306 | JNI_END |
duke@435 | 4307 | |
duke@435 | 4308 | |
duke@435 | 4309 | JNI_ENTRY(void, jni_ReleaseStringCritical(JNIEnv *env, jstring str, const jchar *chars)) |
duke@435 | 4310 | JNIWrapper("ReleaseStringCritical"); |
dcubed@3202 | 4311 | #ifndef USDT2 |
duke@435 | 4312 | DTRACE_PROBE3(hotspot_jni, ReleaseStringCritical__entry, env, str, chars); |
dcubed@3202 | 4313 | #else /* USDT2 */ |
dcubed@3202 | 4314 | HOTSPOT_JNI_RELEASESTRINGCRITICAL_ENTRY( |
dcubed@3202 | 4315 | env, str, (uint16_t *) chars); |
dcubed@3202 | 4316 | #endif /* USDT2 */ |
duke@435 | 4317 | // The str and chars arguments are ignored |
duke@435 | 4318 | GC_locker::unlock_critical(thread); |
dcubed@3202 | 4319 | #ifndef USDT2 |
duke@435 | 4320 | DTRACE_PROBE(hotspot_jni, ReleaseStringCritical__return); |
dcubed@3202 | 4321 | #else /* USDT2 */ |
dcubed@3202 | 4322 | HOTSPOT_JNI_RELEASESTRINGCRITICAL_RETURN( |
dcubed@3202 | 4323 | ); |
dcubed@3202 | 4324 | #endif /* USDT2 */ |
duke@435 | 4325 | JNI_END |
duke@435 | 4326 | |
duke@435 | 4327 | |
duke@435 | 4328 | JNI_ENTRY(jweak, jni_NewWeakGlobalRef(JNIEnv *env, jobject ref)) |
duke@435 | 4329 | JNIWrapper("jni_NewWeakGlobalRef"); |
dcubed@3202 | 4330 | #ifndef USDT2 |
duke@435 | 4331 | DTRACE_PROBE2(hotspot_jni, NewWeakGlobalRef__entry, env, ref); |
dcubed@3202 | 4332 | #else /* USDT2 */ |
dcubed@3202 | 4333 | HOTSPOT_JNI_NEWWEAKGLOBALREF_ENTRY( |
dcubed@3202 | 4334 | env, ref); |
dcubed@3202 | 4335 | #endif /* USDT2 */ |
duke@435 | 4336 | Handle ref_handle(thread, JNIHandles::resolve(ref)); |
duke@435 | 4337 | jweak ret = JNIHandles::make_weak_global(ref_handle); |
dcubed@3202 | 4338 | #ifndef USDT2 |
duke@435 | 4339 | DTRACE_PROBE1(hotspot_jni, NewWeakGlobalRef__return, ret); |
dcubed@3202 | 4340 | #else /* USDT2 */ |
dcubed@3202 | 4341 | HOTSPOT_JNI_NEWWEAKGLOBALREF_RETURN( |
dcubed@3202 | 4342 | ret); |
dcubed@3202 | 4343 | #endif /* USDT2 */ |
duke@435 | 4344 | return ret; |
duke@435 | 4345 | JNI_END |
duke@435 | 4346 | |
duke@435 | 4347 | // Must be JNI_ENTRY (with HandleMark) |
duke@435 | 4348 | JNI_ENTRY(void, jni_DeleteWeakGlobalRef(JNIEnv *env, jweak ref)) |
duke@435 | 4349 | JNIWrapper("jni_DeleteWeakGlobalRef"); |
dcubed@3202 | 4350 | #ifndef USDT2 |
duke@435 | 4351 | DTRACE_PROBE2(hotspot_jni, DeleteWeakGlobalRef__entry, env, ref); |
dcubed@3202 | 4352 | #else /* USDT2 */ |
dcubed@3202 | 4353 | HOTSPOT_JNI_DELETEWEAKGLOBALREF_ENTRY( |
dcubed@3202 | 4354 | env, ref); |
dcubed@3202 | 4355 | #endif /* USDT2 */ |
duke@435 | 4356 | JNIHandles::destroy_weak_global(ref); |
dcubed@3202 | 4357 | #ifndef USDT2 |
duke@435 | 4358 | DTRACE_PROBE(hotspot_jni, DeleteWeakGlobalRef__return); |
dcubed@3202 | 4359 | #else /* USDT2 */ |
dcubed@3202 | 4360 | HOTSPOT_JNI_DELETEWEAKGLOBALREF_RETURN( |
dcubed@3202 | 4361 | ); |
dcubed@3202 | 4362 | #endif /* USDT2 */ |
duke@435 | 4363 | JNI_END |
duke@435 | 4364 | |
duke@435 | 4365 | |
duke@435 | 4366 | JNI_QUICK_ENTRY(jboolean, jni_ExceptionCheck(JNIEnv *env)) |
duke@435 | 4367 | JNIWrapper("jni_ExceptionCheck"); |
dcubed@3202 | 4368 | #ifndef USDT2 |
duke@435 | 4369 | DTRACE_PROBE1(hotspot_jni, ExceptionCheck__entry, env); |
dcubed@3202 | 4370 | #else /* USDT2 */ |
dcubed@3202 | 4371 | HOTSPOT_JNI_EXCEPTIONCHECK_ENTRY( |
dcubed@3202 | 4372 | env); |
dcubed@3202 | 4373 | #endif /* USDT2 */ |
duke@435 | 4374 | jni_check_async_exceptions(thread); |
duke@435 | 4375 | jboolean ret = (thread->has_pending_exception()) ? JNI_TRUE : JNI_FALSE; |
dcubed@3202 | 4376 | #ifndef USDT2 |
duke@435 | 4377 | DTRACE_PROBE1(hotspot_jni, ExceptionCheck__return, ret); |
dcubed@3202 | 4378 | #else /* USDT2 */ |
dcubed@3202 | 4379 | HOTSPOT_JNI_EXCEPTIONCHECK_RETURN( |
dcubed@3202 | 4380 | ret); |
dcubed@3202 | 4381 | #endif /* USDT2 */ |
duke@435 | 4382 | return ret; |
duke@435 | 4383 | JNI_END |
duke@435 | 4384 | |
duke@435 | 4385 | |
duke@435 | 4386 | // Initialization state for three routines below relating to |
duke@435 | 4387 | // java.nio.DirectBuffers |
duke@435 | 4388 | static jint directBufferSupportInitializeStarted = 0; |
duke@435 | 4389 | static volatile jint directBufferSupportInitializeEnded = 0; |
duke@435 | 4390 | static volatile jint directBufferSupportInitializeFailed = 0; |
duke@435 | 4391 | static jclass bufferClass = NULL; |
duke@435 | 4392 | static jclass directBufferClass = NULL; |
duke@435 | 4393 | static jclass directByteBufferClass = NULL; |
duke@435 | 4394 | static jmethodID directByteBufferConstructor = NULL; |
duke@435 | 4395 | static jfieldID directBufferAddressField = NULL; |
duke@435 | 4396 | static jfieldID bufferCapacityField = NULL; |
duke@435 | 4397 | |
duke@435 | 4398 | static jclass lookupOne(JNIEnv* env, const char* name, TRAPS) { |
duke@435 | 4399 | Handle loader; // null (bootstrap) loader |
duke@435 | 4400 | Handle protection_domain; // null protection domain |
duke@435 | 4401 | |
coleenp@2497 | 4402 | TempNewSymbol sym = SymbolTable::new_symbol(name, CHECK_NULL); |
acorn@1092 | 4403 | jclass result = find_class_from_class_loader(env, sym, true, loader, protection_domain, true, CHECK_NULL); |
acorn@1092 | 4404 | |
acorn@1092 | 4405 | if (TraceClassResolution && result != NULL) { |
coleenp@4037 | 4406 | trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result))); |
acorn@1092 | 4407 | } |
acorn@1092 | 4408 | return result; |
duke@435 | 4409 | } |
duke@435 | 4410 | |
duke@435 | 4411 | // These lookups are done with the NULL (bootstrap) ClassLoader to |
duke@435 | 4412 | // circumvent any security checks that would be done by jni_FindClass. |
duke@435 | 4413 | JNI_ENTRY(bool, lookupDirectBufferClasses(JNIEnv* env)) |
duke@435 | 4414 | { |
duke@435 | 4415 | if ((bufferClass = lookupOne(env, "java/nio/Buffer", thread)) == NULL) { return false; } |
duke@435 | 4416 | if ((directBufferClass = lookupOne(env, "sun/nio/ch/DirectBuffer", thread)) == NULL) { return false; } |
duke@435 | 4417 | if ((directByteBufferClass = lookupOne(env, "java/nio/DirectByteBuffer", thread)) == NULL) { return false; } |
duke@435 | 4418 | return true; |
duke@435 | 4419 | } |
duke@435 | 4420 | JNI_END |
duke@435 | 4421 | |
duke@435 | 4422 | |
duke@435 | 4423 | static bool initializeDirectBufferSupport(JNIEnv* env, JavaThread* thread) { |
duke@435 | 4424 | if (directBufferSupportInitializeFailed) { |
duke@435 | 4425 | return false; |
duke@435 | 4426 | } |
duke@435 | 4427 | |
duke@435 | 4428 | if (Atomic::cmpxchg(1, &directBufferSupportInitializeStarted, 0) == 0) { |
duke@435 | 4429 | if (!lookupDirectBufferClasses(env)) { |
duke@435 | 4430 | directBufferSupportInitializeFailed = 1; |
duke@435 | 4431 | return false; |
duke@435 | 4432 | } |
duke@435 | 4433 | |
duke@435 | 4434 | // Make global references for these |
duke@435 | 4435 | bufferClass = (jclass) env->NewGlobalRef(bufferClass); |
duke@435 | 4436 | directBufferClass = (jclass) env->NewGlobalRef(directBufferClass); |
duke@435 | 4437 | directByteBufferClass = (jclass) env->NewGlobalRef(directByteBufferClass); |
duke@435 | 4438 | |
duke@435 | 4439 | // Get needed field and method IDs |
duke@435 | 4440 | directByteBufferConstructor = env->GetMethodID(directByteBufferClass, "<init>", "(JI)V"); |
duke@435 | 4441 | directBufferAddressField = env->GetFieldID(bufferClass, "address", "J"); |
duke@435 | 4442 | bufferCapacityField = env->GetFieldID(bufferClass, "capacity", "I"); |
duke@435 | 4443 | |
duke@435 | 4444 | if ((directByteBufferConstructor == NULL) || |
duke@435 | 4445 | (directBufferAddressField == NULL) || |
duke@435 | 4446 | (bufferCapacityField == NULL)) { |
duke@435 | 4447 | directBufferSupportInitializeFailed = 1; |
duke@435 | 4448 | return false; |
duke@435 | 4449 | } |
duke@435 | 4450 | |
duke@435 | 4451 | directBufferSupportInitializeEnded = 1; |
duke@435 | 4452 | } else { |
duke@435 | 4453 | while (!directBufferSupportInitializeEnded && !directBufferSupportInitializeFailed) { |
xlu@956 | 4454 | // Set state as yield_all can call os:sleep. On Solaris, yield_all calls |
xlu@956 | 4455 | // os::sleep which requires the VM state transition. On other platforms, it |
xlu@956 | 4456 | // is not necessary. The following call to change the VM state is purposely |
xlu@956 | 4457 | // put inside the loop to avoid potential deadlock when multiple threads |
xlu@956 | 4458 | // try to call this method. See 6791815 for more details. |
xlu@956 | 4459 | ThreadInVMfromNative tivn(thread); |
duke@435 | 4460 | os::yield_all(); |
duke@435 | 4461 | } |
duke@435 | 4462 | } |
duke@435 | 4463 | |
duke@435 | 4464 | return !directBufferSupportInitializeFailed; |
duke@435 | 4465 | } |
duke@435 | 4466 | |
duke@435 | 4467 | extern "C" jobject JNICALL jni_NewDirectByteBuffer(JNIEnv *env, void* address, jlong capacity) |
duke@435 | 4468 | { |
duke@435 | 4469 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4470 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4471 | |
duke@435 | 4472 | JNIWrapper("jni_NewDirectByteBuffer"); |
dcubed@3202 | 4473 | #ifndef USDT2 |
duke@435 | 4474 | DTRACE_PROBE3(hotspot_jni, NewDirectByteBuffer__entry, env, address, capacity); |
dcubed@3202 | 4475 | #else /* USDT2 */ |
dcubed@3202 | 4476 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_ENTRY( |
dcubed@3202 | 4477 | env, address, capacity); |
dcubed@3202 | 4478 | #endif /* USDT2 */ |
duke@435 | 4479 | |
duke@435 | 4480 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4481 | if (!initializeDirectBufferSupport(env, thread)) { |
dcubed@3202 | 4482 | #ifndef USDT2 |
duke@435 | 4483 | DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, NULL); |
dcubed@3202 | 4484 | #else /* USDT2 */ |
dcubed@3202 | 4485 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( |
dcubed@3202 | 4486 | NULL); |
dcubed@3202 | 4487 | #endif /* USDT2 */ |
duke@435 | 4488 | return NULL; |
duke@435 | 4489 | } |
duke@435 | 4490 | } |
duke@435 | 4491 | |
duke@435 | 4492 | // Being paranoid about accidental sign extension on address |
duke@435 | 4493 | jlong addr = (jlong) ((uintptr_t) address); |
duke@435 | 4494 | // NOTE that package-private DirectByteBuffer constructor currently |
duke@435 | 4495 | // takes int capacity |
duke@435 | 4496 | jint cap = (jint) capacity; |
duke@435 | 4497 | jobject ret = env->NewObject(directByteBufferClass, directByteBufferConstructor, addr, cap); |
dcubed@3202 | 4498 | #ifndef USDT2 |
duke@435 | 4499 | DTRACE_PROBE1(hotspot_jni, NewDirectByteBuffer__return, ret); |
dcubed@3202 | 4500 | #else /* USDT2 */ |
dcubed@3202 | 4501 | HOTSPOT_JNI_NEWDIRECTBYTEBUFFER_RETURN( |
dcubed@3202 | 4502 | ret); |
dcubed@3202 | 4503 | #endif /* USDT2 */ |
duke@435 | 4504 | return ret; |
duke@435 | 4505 | } |
duke@435 | 4506 | |
dcubed@3202 | 4507 | #ifndef USDT2 |
duke@435 | 4508 | DT_RETURN_MARK_DECL(GetDirectBufferAddress, void*); |
dcubed@3202 | 4509 | #else /* USDT2 */ |
dcubed@3202 | 4510 | DT_RETURN_MARK_DECL(GetDirectBufferAddress, void* |
dcubed@3202 | 4511 | , HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_RETURN((void*) _ret_ref)); |
dcubed@3202 | 4512 | #endif /* USDT2 */ |
duke@435 | 4513 | |
duke@435 | 4514 | extern "C" void* JNICALL jni_GetDirectBufferAddress(JNIEnv *env, jobject buf) |
duke@435 | 4515 | { |
duke@435 | 4516 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4517 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4518 | |
duke@435 | 4519 | JNIWrapper("jni_GetDirectBufferAddress"); |
dcubed@3202 | 4520 | #ifndef USDT2 |
duke@435 | 4521 | DTRACE_PROBE2(hotspot_jni, GetDirectBufferAddress__entry, env, buf); |
dcubed@3202 | 4522 | #else /* USDT2 */ |
dcubed@3202 | 4523 | HOTSPOT_JNI_GETDIRECTBUFFERADDRESS_ENTRY( |
dcubed@3202 | 4524 | env, buf); |
dcubed@3202 | 4525 | #endif /* USDT2 */ |
duke@435 | 4526 | void* ret = NULL; |
duke@435 | 4527 | DT_RETURN_MARK(GetDirectBufferAddress, void*, (const void*&)ret); |
duke@435 | 4528 | |
duke@435 | 4529 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4530 | if (!initializeDirectBufferSupport(env, thread)) { |
duke@435 | 4531 | return 0; |
duke@435 | 4532 | } |
duke@435 | 4533 | } |
duke@435 | 4534 | |
duke@435 | 4535 | if ((buf != NULL) && (!env->IsInstanceOf(buf, directBufferClass))) { |
duke@435 | 4536 | return 0; |
duke@435 | 4537 | } |
duke@435 | 4538 | |
duke@435 | 4539 | ret = (void*)(intptr_t)env->GetLongField(buf, directBufferAddressField); |
duke@435 | 4540 | return ret; |
duke@435 | 4541 | } |
duke@435 | 4542 | |
dcubed@3202 | 4543 | #ifndef USDT2 |
duke@435 | 4544 | DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong); |
dcubed@3202 | 4545 | #else /* USDT2 */ |
dcubed@3202 | 4546 | DT_RETURN_MARK_DECL(GetDirectBufferCapacity, jlong |
dcubed@3202 | 4547 | , HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_RETURN(_ret_ref)); |
dcubed@3202 | 4548 | #endif /* USDT2 */ |
duke@435 | 4549 | |
duke@435 | 4550 | extern "C" jlong JNICALL jni_GetDirectBufferCapacity(JNIEnv *env, jobject buf) |
duke@435 | 4551 | { |
duke@435 | 4552 | // thread_from_jni_environment() will block if VM is gone. |
duke@435 | 4553 | JavaThread* thread = JavaThread::thread_from_jni_environment(env); |
duke@435 | 4554 | |
duke@435 | 4555 | JNIWrapper("jni_GetDirectBufferCapacity"); |
dcubed@3202 | 4556 | #ifndef USDT2 |
duke@435 | 4557 | DTRACE_PROBE2(hotspot_jni, GetDirectBufferCapacity__entry, env, buf); |
dcubed@3202 | 4558 | #else /* USDT2 */ |
dcubed@3202 | 4559 | HOTSPOT_JNI_GETDIRECTBUFFERCAPACITY_ENTRY( |
dcubed@3202 | 4560 | env, buf); |
dcubed@3202 | 4561 | #endif /* USDT2 */ |
duke@435 | 4562 | jlong ret = -1; |
duke@435 | 4563 | DT_RETURN_MARK(GetDirectBufferCapacity, jlong, (const jlong&)ret); |
duke@435 | 4564 | |
duke@435 | 4565 | if (!directBufferSupportInitializeEnded) { |
duke@435 | 4566 | if (!initializeDirectBufferSupport(env, thread)) { |
duke@435 | 4567 | ret = 0; |
duke@435 | 4568 | return ret; |
duke@435 | 4569 | } |
duke@435 | 4570 | } |
duke@435 | 4571 | |
duke@435 | 4572 | if (buf == NULL) { |
duke@435 | 4573 | return -1; |
duke@435 | 4574 | } |
duke@435 | 4575 | |
duke@435 | 4576 | if (!env->IsInstanceOf(buf, directBufferClass)) { |
duke@435 | 4577 | return -1; |
duke@435 | 4578 | } |
duke@435 | 4579 | |
duke@435 | 4580 | // NOTE that capacity is currently an int in the implementation |
duke@435 | 4581 | ret = env->GetIntField(buf, bufferCapacityField); |
duke@435 | 4582 | return ret; |
duke@435 | 4583 | } |
duke@435 | 4584 | |
duke@435 | 4585 | |
duke@435 | 4586 | JNI_LEAF(jint, jni_GetVersion(JNIEnv *env)) |
duke@435 | 4587 | JNIWrapper("GetVersion"); |
dcubed@3202 | 4588 | #ifndef USDT2 |
duke@435 | 4589 | DTRACE_PROBE1(hotspot_jni, GetVersion__entry, env); |
dcubed@3202 | 4590 | #else /* USDT2 */ |
dcubed@3202 | 4591 | HOTSPOT_JNI_GETVERSION_ENTRY( |
dcubed@3202 | 4592 | env); |
dcubed@3202 | 4593 | #endif /* USDT2 */ |
dcubed@3202 | 4594 | #ifndef USDT2 |
duke@435 | 4595 | DTRACE_PROBE1(hotspot_jni, GetVersion__return, CurrentVersion); |
dcubed@3202 | 4596 | #else /* USDT2 */ |
dcubed@3202 | 4597 | HOTSPOT_JNI_GETVERSION_RETURN( |
dcubed@3202 | 4598 | CurrentVersion); |
dcubed@3202 | 4599 | #endif /* USDT2 */ |
duke@435 | 4600 | return CurrentVersion; |
duke@435 | 4601 | JNI_END |
duke@435 | 4602 | |
duke@435 | 4603 | extern struct JavaVM_ main_vm; |
duke@435 | 4604 | |
duke@435 | 4605 | JNI_LEAF(jint, jni_GetJavaVM(JNIEnv *env, JavaVM **vm)) |
duke@435 | 4606 | JNIWrapper("jni_GetJavaVM"); |
dcubed@3202 | 4607 | #ifndef USDT2 |
duke@435 | 4608 | DTRACE_PROBE2(hotspot_jni, GetJavaVM__entry, env, vm); |
dcubed@3202 | 4609 | #else /* USDT2 */ |
dcubed@3202 | 4610 | HOTSPOT_JNI_GETJAVAVM_ENTRY( |
dcubed@3202 | 4611 | env, (void **) vm); |
dcubed@3202 | 4612 | #endif /* USDT2 */ |
duke@435 | 4613 | *vm = (JavaVM *)(&main_vm); |
dcubed@3202 | 4614 | #ifndef USDT2 |
duke@435 | 4615 | DTRACE_PROBE1(hotspot_jni, GetJavaVM__return, JNI_OK); |
dcubed@3202 | 4616 | #else /* USDT2 */ |
dcubed@3202 | 4617 | HOTSPOT_JNI_GETJAVAVM_RETURN( |
dcubed@3202 | 4618 | JNI_OK); |
dcubed@3202 | 4619 | #endif /* USDT2 */ |
duke@435 | 4620 | return JNI_OK; |
duke@435 | 4621 | JNI_END |
duke@435 | 4622 | |
duke@435 | 4623 | // Structure containing all jni functions |
duke@435 | 4624 | struct JNINativeInterface_ jni_NativeInterface = { |
duke@435 | 4625 | NULL, |
duke@435 | 4626 | NULL, |
duke@435 | 4627 | NULL, |
duke@435 | 4628 | |
duke@435 | 4629 | NULL, |
duke@435 | 4630 | |
duke@435 | 4631 | jni_GetVersion, |
duke@435 | 4632 | |
duke@435 | 4633 | jni_DefineClass, |
duke@435 | 4634 | jni_FindClass, |
duke@435 | 4635 | |
duke@435 | 4636 | jni_FromReflectedMethod, |
duke@435 | 4637 | jni_FromReflectedField, |
duke@435 | 4638 | |
duke@435 | 4639 | jni_ToReflectedMethod, |
duke@435 | 4640 | |
duke@435 | 4641 | jni_GetSuperclass, |
duke@435 | 4642 | jni_IsAssignableFrom, |
duke@435 | 4643 | |
duke@435 | 4644 | jni_ToReflectedField, |
duke@435 | 4645 | |
duke@435 | 4646 | jni_Throw, |
duke@435 | 4647 | jni_ThrowNew, |
duke@435 | 4648 | jni_ExceptionOccurred, |
duke@435 | 4649 | jni_ExceptionDescribe, |
duke@435 | 4650 | jni_ExceptionClear, |
duke@435 | 4651 | jni_FatalError, |
duke@435 | 4652 | |
duke@435 | 4653 | jni_PushLocalFrame, |
duke@435 | 4654 | jni_PopLocalFrame, |
duke@435 | 4655 | |
duke@435 | 4656 | jni_NewGlobalRef, |
duke@435 | 4657 | jni_DeleteGlobalRef, |
duke@435 | 4658 | jni_DeleteLocalRef, |
duke@435 | 4659 | jni_IsSameObject, |
duke@435 | 4660 | |
duke@435 | 4661 | jni_NewLocalRef, |
duke@435 | 4662 | jni_EnsureLocalCapacity, |
duke@435 | 4663 | |
duke@435 | 4664 | jni_AllocObject, |
duke@435 | 4665 | jni_NewObject, |
duke@435 | 4666 | jni_NewObjectV, |
duke@435 | 4667 | jni_NewObjectA, |
duke@435 | 4668 | |
duke@435 | 4669 | jni_GetObjectClass, |
duke@435 | 4670 | jni_IsInstanceOf, |
duke@435 | 4671 | |
duke@435 | 4672 | jni_GetMethodID, |
duke@435 | 4673 | |
duke@435 | 4674 | jni_CallObjectMethod, |
duke@435 | 4675 | jni_CallObjectMethodV, |
duke@435 | 4676 | jni_CallObjectMethodA, |
duke@435 | 4677 | jni_CallBooleanMethod, |
duke@435 | 4678 | jni_CallBooleanMethodV, |
duke@435 | 4679 | jni_CallBooleanMethodA, |
duke@435 | 4680 | jni_CallByteMethod, |
duke@435 | 4681 | jni_CallByteMethodV, |
duke@435 | 4682 | jni_CallByteMethodA, |
duke@435 | 4683 | jni_CallCharMethod, |
duke@435 | 4684 | jni_CallCharMethodV, |
duke@435 | 4685 | jni_CallCharMethodA, |
duke@435 | 4686 | jni_CallShortMethod, |
duke@435 | 4687 | jni_CallShortMethodV, |
duke@435 | 4688 | jni_CallShortMethodA, |
duke@435 | 4689 | jni_CallIntMethod, |
duke@435 | 4690 | jni_CallIntMethodV, |
duke@435 | 4691 | jni_CallIntMethodA, |
duke@435 | 4692 | jni_CallLongMethod, |
duke@435 | 4693 | jni_CallLongMethodV, |
duke@435 | 4694 | jni_CallLongMethodA, |
duke@435 | 4695 | jni_CallFloatMethod, |
duke@435 | 4696 | jni_CallFloatMethodV, |
duke@435 | 4697 | jni_CallFloatMethodA, |
duke@435 | 4698 | jni_CallDoubleMethod, |
duke@435 | 4699 | jni_CallDoubleMethodV, |
duke@435 | 4700 | jni_CallDoubleMethodA, |
duke@435 | 4701 | jni_CallVoidMethod, |
duke@435 | 4702 | jni_CallVoidMethodV, |
duke@435 | 4703 | jni_CallVoidMethodA, |
duke@435 | 4704 | |
duke@435 | 4705 | jni_CallNonvirtualObjectMethod, |
duke@435 | 4706 | jni_CallNonvirtualObjectMethodV, |
duke@435 | 4707 | jni_CallNonvirtualObjectMethodA, |
duke@435 | 4708 | jni_CallNonvirtualBooleanMethod, |
duke@435 | 4709 | jni_CallNonvirtualBooleanMethodV, |
duke@435 | 4710 | jni_CallNonvirtualBooleanMethodA, |
duke@435 | 4711 | jni_CallNonvirtualByteMethod, |
duke@435 | 4712 | jni_CallNonvirtualByteMethodV, |
duke@435 | 4713 | jni_CallNonvirtualByteMethodA, |
duke@435 | 4714 | jni_CallNonvirtualCharMethod, |
duke@435 | 4715 | jni_CallNonvirtualCharMethodV, |
duke@435 | 4716 | jni_CallNonvirtualCharMethodA, |
duke@435 | 4717 | jni_CallNonvirtualShortMethod, |
duke@435 | 4718 | jni_CallNonvirtualShortMethodV, |
duke@435 | 4719 | jni_CallNonvirtualShortMethodA, |
duke@435 | 4720 | jni_CallNonvirtualIntMethod, |
duke@435 | 4721 | jni_CallNonvirtualIntMethodV, |
duke@435 | 4722 | jni_CallNonvirtualIntMethodA, |
duke@435 | 4723 | jni_CallNonvirtualLongMethod, |
duke@435 | 4724 | jni_CallNonvirtualLongMethodV, |
duke@435 | 4725 | jni_CallNonvirtualLongMethodA, |
duke@435 | 4726 | jni_CallNonvirtualFloatMethod, |
duke@435 | 4727 | jni_CallNonvirtualFloatMethodV, |
duke@435 | 4728 | jni_CallNonvirtualFloatMethodA, |
duke@435 | 4729 | jni_CallNonvirtualDoubleMethod, |
duke@435 | 4730 | jni_CallNonvirtualDoubleMethodV, |
duke@435 | 4731 | jni_CallNonvirtualDoubleMethodA, |
duke@435 | 4732 | jni_CallNonvirtualVoidMethod, |
duke@435 | 4733 | jni_CallNonvirtualVoidMethodV, |
duke@435 | 4734 | jni_CallNonvirtualVoidMethodA, |
duke@435 | 4735 | |
duke@435 | 4736 | jni_GetFieldID, |
duke@435 | 4737 | |
duke@435 | 4738 | jni_GetObjectField, |
duke@435 | 4739 | jni_GetBooleanField, |
duke@435 | 4740 | jni_GetByteField, |
duke@435 | 4741 | jni_GetCharField, |
duke@435 | 4742 | jni_GetShortField, |
duke@435 | 4743 | jni_GetIntField, |
duke@435 | 4744 | jni_GetLongField, |
duke@435 | 4745 | jni_GetFloatField, |
duke@435 | 4746 | jni_GetDoubleField, |
duke@435 | 4747 | |
duke@435 | 4748 | jni_SetObjectField, |
duke@435 | 4749 | jni_SetBooleanField, |
duke@435 | 4750 | jni_SetByteField, |
duke@435 | 4751 | jni_SetCharField, |
duke@435 | 4752 | jni_SetShortField, |
duke@435 | 4753 | jni_SetIntField, |
duke@435 | 4754 | jni_SetLongField, |
duke@435 | 4755 | jni_SetFloatField, |
duke@435 | 4756 | jni_SetDoubleField, |
duke@435 | 4757 | |
duke@435 | 4758 | jni_GetStaticMethodID, |
duke@435 | 4759 | |
duke@435 | 4760 | jni_CallStaticObjectMethod, |
duke@435 | 4761 | jni_CallStaticObjectMethodV, |
duke@435 | 4762 | jni_CallStaticObjectMethodA, |
duke@435 | 4763 | jni_CallStaticBooleanMethod, |
duke@435 | 4764 | jni_CallStaticBooleanMethodV, |
duke@435 | 4765 | jni_CallStaticBooleanMethodA, |
duke@435 | 4766 | jni_CallStaticByteMethod, |
duke@435 | 4767 | jni_CallStaticByteMethodV, |
duke@435 | 4768 | jni_CallStaticByteMethodA, |
duke@435 | 4769 | jni_CallStaticCharMethod, |
duke@435 | 4770 | jni_CallStaticCharMethodV, |
duke@435 | 4771 | jni_CallStaticCharMethodA, |
duke@435 | 4772 | jni_CallStaticShortMethod, |
duke@435 | 4773 | jni_CallStaticShortMethodV, |
duke@435 | 4774 | jni_CallStaticShortMethodA, |
duke@435 | 4775 | jni_CallStaticIntMethod, |
duke@435 | 4776 | jni_CallStaticIntMethodV, |
duke@435 | 4777 | jni_CallStaticIntMethodA, |
duke@435 | 4778 | jni_CallStaticLongMethod, |
duke@435 | 4779 | jni_CallStaticLongMethodV, |
duke@435 | 4780 | jni_CallStaticLongMethodA, |
duke@435 | 4781 | jni_CallStaticFloatMethod, |
duke@435 | 4782 | jni_CallStaticFloatMethodV, |
duke@435 | 4783 | jni_CallStaticFloatMethodA, |
duke@435 | 4784 | jni_CallStaticDoubleMethod, |
duke@435 | 4785 | jni_CallStaticDoubleMethodV, |
duke@435 | 4786 | jni_CallStaticDoubleMethodA, |
duke@435 | 4787 | jni_CallStaticVoidMethod, |
duke@435 | 4788 | jni_CallStaticVoidMethodV, |
duke@435 | 4789 | jni_CallStaticVoidMethodA, |
duke@435 | 4790 | |
duke@435 | 4791 | jni_GetStaticFieldID, |
duke@435 | 4792 | |
duke@435 | 4793 | jni_GetStaticObjectField, |
duke@435 | 4794 | jni_GetStaticBooleanField, |
duke@435 | 4795 | jni_GetStaticByteField, |
duke@435 | 4796 | jni_GetStaticCharField, |
duke@435 | 4797 | jni_GetStaticShortField, |
duke@435 | 4798 | jni_GetStaticIntField, |
duke@435 | 4799 | jni_GetStaticLongField, |
duke@435 | 4800 | jni_GetStaticFloatField, |
duke@435 | 4801 | jni_GetStaticDoubleField, |
duke@435 | 4802 | |
duke@435 | 4803 | jni_SetStaticObjectField, |
duke@435 | 4804 | jni_SetStaticBooleanField, |
duke@435 | 4805 | jni_SetStaticByteField, |
duke@435 | 4806 | jni_SetStaticCharField, |
duke@435 | 4807 | jni_SetStaticShortField, |
duke@435 | 4808 | jni_SetStaticIntField, |
duke@435 | 4809 | jni_SetStaticLongField, |
duke@435 | 4810 | jni_SetStaticFloatField, |
duke@435 | 4811 | jni_SetStaticDoubleField, |
duke@435 | 4812 | |
duke@435 | 4813 | jni_NewString, |
duke@435 | 4814 | jni_GetStringLength, |
duke@435 | 4815 | jni_GetStringChars, |
duke@435 | 4816 | jni_ReleaseStringChars, |
duke@435 | 4817 | |
duke@435 | 4818 | jni_NewStringUTF, |
duke@435 | 4819 | jni_GetStringUTFLength, |
duke@435 | 4820 | jni_GetStringUTFChars, |
duke@435 | 4821 | jni_ReleaseStringUTFChars, |
duke@435 | 4822 | |
duke@435 | 4823 | jni_GetArrayLength, |
duke@435 | 4824 | |
duke@435 | 4825 | jni_NewObjectArray, |
duke@435 | 4826 | jni_GetObjectArrayElement, |
duke@435 | 4827 | jni_SetObjectArrayElement, |
duke@435 | 4828 | |
duke@435 | 4829 | jni_NewBooleanArray, |
duke@435 | 4830 | jni_NewByteArray, |
duke@435 | 4831 | jni_NewCharArray, |
duke@435 | 4832 | jni_NewShortArray, |
duke@435 | 4833 | jni_NewIntArray, |
duke@435 | 4834 | jni_NewLongArray, |
duke@435 | 4835 | jni_NewFloatArray, |
duke@435 | 4836 | jni_NewDoubleArray, |
duke@435 | 4837 | |
duke@435 | 4838 | jni_GetBooleanArrayElements, |
duke@435 | 4839 | jni_GetByteArrayElements, |
duke@435 | 4840 | jni_GetCharArrayElements, |
duke@435 | 4841 | jni_GetShortArrayElements, |
duke@435 | 4842 | jni_GetIntArrayElements, |
duke@435 | 4843 | jni_GetLongArrayElements, |
duke@435 | 4844 | jni_GetFloatArrayElements, |
duke@435 | 4845 | jni_GetDoubleArrayElements, |
duke@435 | 4846 | |
duke@435 | 4847 | jni_ReleaseBooleanArrayElements, |
duke@435 | 4848 | jni_ReleaseByteArrayElements, |
duke@435 | 4849 | jni_ReleaseCharArrayElements, |
duke@435 | 4850 | jni_ReleaseShortArrayElements, |
duke@435 | 4851 | jni_ReleaseIntArrayElements, |
duke@435 | 4852 | jni_ReleaseLongArrayElements, |
duke@435 | 4853 | jni_ReleaseFloatArrayElements, |
duke@435 | 4854 | jni_ReleaseDoubleArrayElements, |
duke@435 | 4855 | |
duke@435 | 4856 | jni_GetBooleanArrayRegion, |
duke@435 | 4857 | jni_GetByteArrayRegion, |
duke@435 | 4858 | jni_GetCharArrayRegion, |
duke@435 | 4859 | jni_GetShortArrayRegion, |
duke@435 | 4860 | jni_GetIntArrayRegion, |
duke@435 | 4861 | jni_GetLongArrayRegion, |
duke@435 | 4862 | jni_GetFloatArrayRegion, |
duke@435 | 4863 | jni_GetDoubleArrayRegion, |
duke@435 | 4864 | |
duke@435 | 4865 | jni_SetBooleanArrayRegion, |
duke@435 | 4866 | jni_SetByteArrayRegion, |
duke@435 | 4867 | jni_SetCharArrayRegion, |
duke@435 | 4868 | jni_SetShortArrayRegion, |
duke@435 | 4869 | jni_SetIntArrayRegion, |
duke@435 | 4870 | jni_SetLongArrayRegion, |
duke@435 | 4871 | jni_SetFloatArrayRegion, |
duke@435 | 4872 | jni_SetDoubleArrayRegion, |
duke@435 | 4873 | |
duke@435 | 4874 | jni_RegisterNatives, |
duke@435 | 4875 | jni_UnregisterNatives, |
duke@435 | 4876 | |
duke@435 | 4877 | jni_MonitorEnter, |
duke@435 | 4878 | jni_MonitorExit, |
duke@435 | 4879 | |
duke@435 | 4880 | jni_GetJavaVM, |
duke@435 | 4881 | |
duke@435 | 4882 | jni_GetStringRegion, |
duke@435 | 4883 | jni_GetStringUTFRegion, |
duke@435 | 4884 | |
duke@435 | 4885 | jni_GetPrimitiveArrayCritical, |
duke@435 | 4886 | jni_ReleasePrimitiveArrayCritical, |
duke@435 | 4887 | |
duke@435 | 4888 | jni_GetStringCritical, |
duke@435 | 4889 | jni_ReleaseStringCritical, |
duke@435 | 4890 | |
duke@435 | 4891 | jni_NewWeakGlobalRef, |
duke@435 | 4892 | jni_DeleteWeakGlobalRef, |
duke@435 | 4893 | |
duke@435 | 4894 | jni_ExceptionCheck, |
duke@435 | 4895 | |
duke@435 | 4896 | jni_NewDirectByteBuffer, |
duke@435 | 4897 | jni_GetDirectBufferAddress, |
duke@435 | 4898 | jni_GetDirectBufferCapacity, |
duke@435 | 4899 | |
duke@435 | 4900 | // New 1_6 features |
duke@435 | 4901 | |
duke@435 | 4902 | jni_GetObjectRefType |
duke@435 | 4903 | }; |
duke@435 | 4904 | |
duke@435 | 4905 | |
duke@435 | 4906 | // For jvmti use to modify jni function table. |
duke@435 | 4907 | // Java threads in native contiues to run until it is transitioned |
duke@435 | 4908 | // to VM at safepoint. Before the transition or before it is blocked |
duke@435 | 4909 | // for safepoint it may access jni function table. VM could crash if |
duke@435 | 4910 | // any java thread access the jni function table in the middle of memcpy. |
duke@435 | 4911 | // To avoid this each function pointers are copied automically. |
duke@435 | 4912 | void copy_jni_function_table(const struct JNINativeInterface_ *new_jni_NativeInterface) { |
duke@435 | 4913 | assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
duke@435 | 4914 | intptr_t *a = (intptr_t *) jni_functions(); |
duke@435 | 4915 | intptr_t *b = (intptr_t *) new_jni_NativeInterface; |
duke@435 | 4916 | for (uint i=0; i < sizeof(struct JNINativeInterface_)/sizeof(void *); i++) { |
duke@435 | 4917 | Atomic::store_ptr(*b++, a++); |
duke@435 | 4918 | } |
duke@435 | 4919 | } |
duke@435 | 4920 | |
duke@435 | 4921 | void quicken_jni_functions() { |
duke@435 | 4922 | // Replace Get<Primitive>Field with fast versions |
duke@435 | 4923 | if (UseFastJNIAccessors && !JvmtiExport::can_post_field_access() |
duke@435 | 4924 | && !VerifyJNIFields && !TraceJNICalls && !CountJNICalls && !CheckJNICalls |
duke@435 | 4925 | #if defined(_WINDOWS) && defined(IA32) && defined(COMPILER2) |
duke@435 | 4926 | // windows x86 currently needs SEH wrapper and the gain of the fast |
duke@435 | 4927 | // versions currently isn't certain for server vm on uniprocessor. |
duke@435 | 4928 | && os::is_MP() |
duke@435 | 4929 | #endif |
duke@435 | 4930 | ) { |
duke@435 | 4931 | address func; |
duke@435 | 4932 | func = JNI_FastGetField::generate_fast_get_boolean_field(); |
duke@435 | 4933 | if (func != (address)-1) { |
duke@435 | 4934 | jni_NativeInterface.GetBooleanField = (GetBooleanField_t)func; |
duke@435 | 4935 | } |
duke@435 | 4936 | func = JNI_FastGetField::generate_fast_get_byte_field(); |
duke@435 | 4937 | if (func != (address)-1) { |
duke@435 | 4938 | jni_NativeInterface.GetByteField = (GetByteField_t)func; |
duke@435 | 4939 | } |
duke@435 | 4940 | func = JNI_FastGetField::generate_fast_get_char_field(); |
duke@435 | 4941 | if (func != (address)-1) { |
duke@435 | 4942 | jni_NativeInterface.GetCharField = (GetCharField_t)func; |
duke@435 | 4943 | } |
duke@435 | 4944 | func = JNI_FastGetField::generate_fast_get_short_field(); |
duke@435 | 4945 | if (func != (address)-1) { |
duke@435 | 4946 | jni_NativeInterface.GetShortField = (GetShortField_t)func; |
duke@435 | 4947 | } |
duke@435 | 4948 | func = JNI_FastGetField::generate_fast_get_int_field(); |
duke@435 | 4949 | if (func != (address)-1) { |
duke@435 | 4950 | jni_NativeInterface.GetIntField = (GetIntField_t)func; |
duke@435 | 4951 | } |
duke@435 | 4952 | func = JNI_FastGetField::generate_fast_get_long_field(); |
duke@435 | 4953 | if (func != (address)-1) { |
duke@435 | 4954 | jni_NativeInterface.GetLongField = (GetLongField_t)func; |
duke@435 | 4955 | } |
duke@435 | 4956 | func = JNI_FastGetField::generate_fast_get_float_field(); |
duke@435 | 4957 | if (func != (address)-1) { |
duke@435 | 4958 | jni_NativeInterface.GetFloatField = (GetFloatField_t)func; |
duke@435 | 4959 | } |
duke@435 | 4960 | func = JNI_FastGetField::generate_fast_get_double_field(); |
duke@435 | 4961 | if (func != (address)-1) { |
duke@435 | 4962 | jni_NativeInterface.GetDoubleField = (GetDoubleField_t)func; |
duke@435 | 4963 | } |
duke@435 | 4964 | } |
duke@435 | 4965 | } |
duke@435 | 4966 | |
duke@435 | 4967 | // Returns the function structure |
duke@435 | 4968 | struct JNINativeInterface_* jni_functions() { |
jprovino@4165 | 4969 | #if INCLUDE_JNI_CHECK |
duke@435 | 4970 | if (CheckJNICalls) return jni_functions_check(); |
jprovino@4165 | 4971 | #endif // INCLUDE_JNI_CHECK |
duke@435 | 4972 | return &jni_NativeInterface; |
duke@435 | 4973 | } |
duke@435 | 4974 | |
duke@435 | 4975 | // Returns the function structure |
duke@435 | 4976 | struct JNINativeInterface_* jni_functions_nocheck() { |
duke@435 | 4977 | return &jni_NativeInterface; |
duke@435 | 4978 | } |
duke@435 | 4979 | |
duke@435 | 4980 | |
duke@435 | 4981 | // Invocation API |
duke@435 | 4982 | |
duke@435 | 4983 | |
duke@435 | 4984 | // Forward declaration |
duke@435 | 4985 | extern const struct JNIInvokeInterface_ jni_InvokeInterface; |
duke@435 | 4986 | |
duke@435 | 4987 | // Global invocation API vars |
duke@435 | 4988 | volatile jint vm_created = 0; |
duke@435 | 4989 | // Indicate whether it is safe to recreate VM |
duke@435 | 4990 | volatile jint safe_to_recreate_vm = 1; |
duke@435 | 4991 | struct JavaVM_ main_vm = {&jni_InvokeInterface}; |
duke@435 | 4992 | |
duke@435 | 4993 | |
duke@435 | 4994 | #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ |
duke@435 | 4995 | enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; |
duke@435 | 4996 | |
dcubed@3202 | 4997 | #ifndef USDT2 |
duke@435 | 4998 | HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); |
duke@435 | 4999 | DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint); |
dcubed@3202 | 5000 | #else /* USDT2 */ |
dcubed@3202 | 5001 | DT_RETURN_MARK_DECL(GetDefaultJavaVMInitArgs, jint |
dcubed@3202 | 5002 | , HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_RETURN(_ret_ref)); |
dcubed@3202 | 5003 | #endif /* USDT2 */ |
duke@435 | 5004 | |
duke@435 | 5005 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetDefaultJavaVMInitArgs(void *args_) { |
dcubed@3202 | 5006 | #ifndef USDT2 |
duke@435 | 5007 | HS_DTRACE_PROBE1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, args_); |
dcubed@3202 | 5008 | #else /* USDT2 */ |
dcubed@3202 | 5009 | HOTSPOT_JNI_GETDEFAULTJAVAVMINITARGS_ENTRY( |
dcubed@3202 | 5010 | args_); |
dcubed@3202 | 5011 | #endif /* USDT2 */ |
duke@435 | 5012 | JDK1_1InitArgs *args = (JDK1_1InitArgs *)args_; |
duke@435 | 5013 | jint ret = JNI_ERR; |
duke@435 | 5014 | DT_RETURN_MARK(GetDefaultJavaVMInitArgs, jint, (const jint&)ret); |
duke@435 | 5015 | |
duke@435 | 5016 | if (Threads::is_supported_jni_version(args->version)) { |
duke@435 | 5017 | ret = JNI_OK; |
duke@435 | 5018 | } |
duke@435 | 5019 | // 1.1 style no longer supported in hotspot. |
duke@435 | 5020 | // According the JNI spec, we should update args->version on return. |
duke@435 | 5021 | // We also use the structure to communicate with launcher about default |
duke@435 | 5022 | // stack size. |
duke@435 | 5023 | if (args->version == JNI_VERSION_1_1) { |
duke@435 | 5024 | args->version = JNI_VERSION_1_2; |
duke@435 | 5025 | // javaStackSize is int in arguments structure |
duke@435 | 5026 | assert(jlong(ThreadStackSize) * K < INT_MAX, "integer overflow"); |
duke@435 | 5027 | args->javaStackSize = (jint)(ThreadStackSize * K); |
duke@435 | 5028 | } |
duke@435 | 5029 | return ret; |
duke@435 | 5030 | } |
duke@435 | 5031 | |
brutisso@2976 | 5032 | #ifndef PRODUCT |
brutisso@2976 | 5033 | |
sla@5237 | 5034 | #include "gc_implementation/shared/gcTimer.hpp" |
stefank@3335 | 5035 | #include "gc_interface/collectedHeap.hpp" |
tschatzl@5165 | 5036 | #if INCLUDE_ALL_GCS |
tschatzl@5165 | 5037 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
tschatzl@5165 | 5038 | #endif |
brutisso@2976 | 5039 | #include "utilities/quickSort.hpp" |
mikael@4290 | 5040 | #if INCLUDE_VM_STRUCTS |
mikael@4290 | 5041 | #include "runtime/vmStructs.hpp" |
mikael@4290 | 5042 | #endif |
brutisso@2976 | 5043 | |
stefank@3335 | 5044 | #define run_unit_test(unit_test_function_call) \ |
stefank@3335 | 5045 | tty->print_cr("Running test: " #unit_test_function_call); \ |
stefank@3335 | 5046 | unit_test_function_call |
stefank@3335 | 5047 | |
stefank@5578 | 5048 | // Forward declaration |
stefank@5578 | 5049 | void TestReservedSpace_test(); |
stefank@5578 | 5050 | void TestReserveMemorySpecial_test(); |
stefank@5578 | 5051 | |
brutisso@2976 | 5052 | void execute_internal_vm_tests() { |
brutisso@2976 | 5053 | if (ExecuteInternalVMTests) { |
stefank@3335 | 5054 | tty->print_cr("Running internal VM tests"); |
stefank@5578 | 5055 | run_unit_test(TestReservedSpace_test()); |
stefank@5578 | 5056 | run_unit_test(TestReserveMemorySpecial_test()); |
mikael@4889 | 5057 | run_unit_test(GlobalDefinitions::test_globals()); |
sla@5237 | 5058 | run_unit_test(GCTimerAllTest::all()); |
stefank@3335 | 5059 | run_unit_test(arrayOopDesc::test_max_array_length()); |
stefank@3335 | 5060 | run_unit_test(CollectedHeap::test_is_in()); |
stefank@3335 | 5061 | run_unit_test(QuickSort::test_quick_sort()); |
coleenp@3865 | 5062 | run_unit_test(AltHashing::test_alt_hash()); |
mikael@4290 | 5063 | #if INCLUDE_VM_STRUCTS |
mikael@4290 | 5064 | run_unit_test(VMStructs::test()); |
mikael@4290 | 5065 | #endif |
tschatzl@5165 | 5066 | #if INCLUDE_ALL_GCS |
tschatzl@5165 | 5067 | run_unit_test(HeapRegionRemSet::test_prt()); |
tschatzl@5165 | 5068 | #endif |
brutisso@3266 | 5069 | tty->print_cr("All internal VM tests passed"); |
brutisso@2976 | 5070 | } |
brutisso@2976 | 5071 | } |
brutisso@2976 | 5072 | |
stefank@3335 | 5073 | #undef run_unit_test |
stefank@3335 | 5074 | |
brutisso@2976 | 5075 | #endif |
brutisso@2976 | 5076 | |
dcubed@3202 | 5077 | #ifndef USDT2 |
duke@435 | 5078 | HS_DTRACE_PROBE_DECL3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
duke@435 | 5079 | DT_RETURN_MARK_DECL(CreateJavaVM, jint); |
dcubed@3202 | 5080 | #else /* USDT2 */ |
dcubed@3202 | 5081 | DT_RETURN_MARK_DECL(CreateJavaVM, jint |
dcubed@3202 | 5082 | , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref)); |
dcubed@3202 | 5083 | #endif /* USDT2 */ |
duke@435 | 5084 | |
duke@435 | 5085 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) { |
dcubed@3202 | 5086 | #ifndef USDT2 |
duke@435 | 5087 | HS_DTRACE_PROBE3(hotspot_jni, CreateJavaVM__entry, vm, penv, args); |
dcubed@3202 | 5088 | #else /* USDT2 */ |
dcubed@3202 | 5089 | HOTSPOT_JNI_CREATEJAVAVM_ENTRY( |
dcubed@3202 | 5090 | (void **) vm, penv, args); |
dcubed@3202 | 5091 | #endif /* USDT2 */ |
duke@435 | 5092 | |
duke@435 | 5093 | jint result = JNI_ERR; |
duke@435 | 5094 | DT_RETURN_MARK(CreateJavaVM, jint, (const jint&)result); |
duke@435 | 5095 | |
twisti@1513 | 5096 | // We're about to use Atomic::xchg for synchronization. Some Zero |
twisti@1513 | 5097 | // platforms use the GCC builtin __sync_lock_test_and_set for this, |
twisti@1513 | 5098 | // but __sync_lock_test_and_set is not guaranteed to do what we want |
twisti@1513 | 5099 | // on all architectures. So we check it works before relying on it. |
twisti@1513 | 5100 | #if defined(ZERO) && defined(ASSERT) |
twisti@1513 | 5101 | { |
twisti@1513 | 5102 | jint a = 0xcafebabe; |
twisti@1513 | 5103 | jint b = Atomic::xchg(0xdeadbeef, &a); |
twisti@1513 | 5104 | void *c = &a; |
twisti@1513 | 5105 | void *d = Atomic::xchg_ptr(&b, &c); |
twisti@1567 | 5106 | assert(a == (jint) 0xdeadbeef && b == (jint) 0xcafebabe, "Atomic::xchg() works"); |
twisti@1513 | 5107 | assert(c == &b && d == &a, "Atomic::xchg_ptr() works"); |
twisti@1513 | 5108 | } |
twisti@1513 | 5109 | #endif // ZERO && ASSERT |
twisti@1513 | 5110 | |
duke@435 | 5111 | // At the moment it's only possible to have one Java VM, |
duke@435 | 5112 | // since some of the runtime state is in global variables. |
duke@435 | 5113 | |
duke@435 | 5114 | // We cannot use our mutex locks here, since they only work on |
duke@435 | 5115 | // Threads. We do an atomic compare and exchange to ensure only |
duke@435 | 5116 | // one thread can call this method at a time |
duke@435 | 5117 | |
duke@435 | 5118 | // We use Atomic::xchg rather than Atomic::add/dec since on some platforms |
duke@435 | 5119 | // the add/dec implementations are dependent on whether we are running |
duke@435 | 5120 | // on a multiprocessor, and at this stage of initialization the os::is_MP |
duke@435 | 5121 | // function used to determine this will always return false. Atomic::xchg |
duke@435 | 5122 | // does not have this problem. |
duke@435 | 5123 | if (Atomic::xchg(1, &vm_created) == 1) { |
coleenp@5362 | 5124 | return JNI_EEXIST; // already created, or create attempt in progress |
duke@435 | 5125 | } |
duke@435 | 5126 | if (Atomic::xchg(0, &safe_to_recreate_vm) == 0) { |
duke@435 | 5127 | return JNI_ERR; // someone tried and failed and retry not allowed. |
duke@435 | 5128 | } |
duke@435 | 5129 | |
duke@435 | 5130 | assert(vm_created == 1, "vm_created is true during the creation"); |
duke@435 | 5131 | |
duke@435 | 5132 | /** |
duke@435 | 5133 | * Certain errors during initialization are recoverable and do not |
duke@435 | 5134 | * prevent this method from being called again at a later time |
duke@435 | 5135 | * (perhaps with different arguments). However, at a certain |
duke@435 | 5136 | * point during initialization if an error occurs we cannot allow |
duke@435 | 5137 | * this function to be called again (or it will crash). In those |
duke@435 | 5138 | * situations, the 'canTryAgain' flag is set to false, which atomically |
duke@435 | 5139 | * sets safe_to_recreate_vm to 1, such that any new call to |
duke@435 | 5140 | * JNI_CreateJavaVM will immediately fail using the above logic. |
duke@435 | 5141 | */ |
duke@435 | 5142 | bool can_try_again = true; |
duke@435 | 5143 | |
duke@435 | 5144 | result = Threads::create_vm((JavaVMInitArgs*) args, &can_try_again); |
duke@435 | 5145 | if (result == JNI_OK) { |
duke@435 | 5146 | JavaThread *thread = JavaThread::current(); |
duke@435 | 5147 | /* thread is thread_in_vm here */ |
duke@435 | 5148 | *vm = (JavaVM *)(&main_vm); |
duke@435 | 5149 | *(JNIEnv**)penv = thread->jni_environment(); |
duke@435 | 5150 | |
duke@435 | 5151 | // Tracks the time application was running before GC |
duke@435 | 5152 | RuntimeService::record_application_start(); |
duke@435 | 5153 | |
duke@435 | 5154 | // Notify JVMTI |
duke@435 | 5155 | if (JvmtiExport::should_post_thread_life()) { |
duke@435 | 5156 | JvmtiExport::post_thread_start(thread); |
duke@435 | 5157 | } |
phh@3427 | 5158 | |
sla@5237 | 5159 | EventThreadStart event; |
sla@5237 | 5160 | if (event.should_commit()) { |
sla@5237 | 5161 | event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj())); |
sla@5237 | 5162 | event.commit(); |
sla@5237 | 5163 | } |
phh@3427 | 5164 | |
dcubed@5365 | 5165 | #ifndef PRODUCT |
dcubed@5365 | 5166 | #ifndef TARGET_OS_FAMILY_windows |
dcubed@5365 | 5167 | #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f() |
dcubed@5365 | 5168 | #endif |
dcubed@5365 | 5169 | |
duke@435 | 5170 | // Check if we should compile all classes on bootclasspath |
dcubed@5365 | 5171 | if (CompileTheWorld) ClassLoader::compile_the_world(); |
dcubed@5365 | 5172 | if (ReplayCompiles) ciReplay::replay(thread); |
dcubed@5365 | 5173 | |
dcubed@5365 | 5174 | // Some platforms (like Win*) need a wrapper around these test |
dcubed@5365 | 5175 | // functions in order to properly handle error conditions. |
dcubed@5365 | 5176 | CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler); |
dcubed@5365 | 5177 | CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests); |
dcubed@5365 | 5178 | #endif |
dcubed@5365 | 5179 | |
duke@435 | 5180 | // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. |
duke@435 | 5181 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5182 | } else { |
duke@435 | 5183 | if (can_try_again) { |
duke@435 | 5184 | // reset safe_to_recreate_vm to 1 so that retrial would be possible |
duke@435 | 5185 | safe_to_recreate_vm = 1; |
duke@435 | 5186 | } |
duke@435 | 5187 | |
duke@435 | 5188 | // Creation failed. We must reset vm_created |
duke@435 | 5189 | *vm = 0; |
duke@435 | 5190 | *(JNIEnv**)penv = 0; |
duke@435 | 5191 | // reset vm_created last to avoid race condition. Use OrderAccess to |
duke@435 | 5192 | // control both compiler and architectural-based reordering. |
duke@435 | 5193 | OrderAccess::release_store(&vm_created, 0); |
duke@435 | 5194 | } |
duke@435 | 5195 | |
duke@435 | 5196 | return result; |
duke@435 | 5197 | } |
duke@435 | 5198 | |
dcubed@3202 | 5199 | #ifndef USDT2 |
duke@435 | 5200 | HS_DTRACE_PROBE_DECL3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
duke@435 | 5201 | JavaVM**, jsize, jsize*); |
duke@435 | 5202 | HS_DTRACE_PROBE_DECL1(hotspot_jni, GetCreatedJavaVMs__return, jint); |
dcubed@3202 | 5203 | #endif /* !USDT2 */ |
duke@435 | 5204 | |
duke@435 | 5205 | _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) { |
duke@435 | 5206 | // See bug 4367188, the wrapper can sometimes cause VM crashes |
duke@435 | 5207 | // JNIWrapper("GetCreatedJavaVMs"); |
dcubed@3202 | 5208 | #ifndef USDT2 |
duke@435 | 5209 | HS_DTRACE_PROBE3(hotspot_jni, GetCreatedJavaVMs__entry, \ |
duke@435 | 5210 | vm_buf, bufLen, numVMs); |
dcubed@3202 | 5211 | #else /* USDT2 */ |
dcubed@3202 | 5212 | HOTSPOT_JNI_GETCREATEDJAVAVMS_ENTRY( |
dcubed@3202 | 5213 | (void **) vm_buf, bufLen, (uintptr_t *) numVMs); |
dcubed@3202 | 5214 | #endif /* USDT2 */ |
duke@435 | 5215 | if (vm_created) { |
duke@435 | 5216 | if (numVMs != NULL) *numVMs = 1; |
duke@435 | 5217 | if (bufLen > 0) *vm_buf = (JavaVM *)(&main_vm); |
duke@435 | 5218 | } else { |
duke@435 | 5219 | if (numVMs != NULL) *numVMs = 0; |
duke@435 | 5220 | } |
dcubed@3202 | 5221 | #ifndef USDT2 |
duke@435 | 5222 | HS_DTRACE_PROBE1(hotspot_jni, GetCreatedJavaVMs__return, JNI_OK); |
dcubed@3202 | 5223 | #else /* USDT2 */ |
dcubed@3202 | 5224 | HOTSPOT_JNI_GETCREATEDJAVAVMS_RETURN( |
dcubed@3202 | 5225 | JNI_OK); |
dcubed@3202 | 5226 | #endif /* USDT2 */ |
duke@435 | 5227 | return JNI_OK; |
duke@435 | 5228 | } |
duke@435 | 5229 | |
duke@435 | 5230 | extern "C" { |
duke@435 | 5231 | |
dcubed@3202 | 5232 | #ifndef USDT2 |
duke@435 | 5233 | DT_RETURN_MARK_DECL(DestroyJavaVM, jint); |
dcubed@3202 | 5234 | #else /* USDT2 */ |
dcubed@3202 | 5235 | DT_RETURN_MARK_DECL(DestroyJavaVM, jint |
dcubed@3202 | 5236 | , HOTSPOT_JNI_DESTROYJAVAVM_RETURN(_ret_ref)); |
dcubed@3202 | 5237 | #endif /* USDT2 */ |
duke@435 | 5238 | |
duke@435 | 5239 | jint JNICALL jni_DestroyJavaVM(JavaVM *vm) { |
dcubed@3202 | 5240 | #ifndef USDT2 |
duke@435 | 5241 | DTRACE_PROBE1(hotspot_jni, DestroyJavaVM__entry, vm); |
dcubed@3202 | 5242 | #else /* USDT2 */ |
dcubed@3202 | 5243 | HOTSPOT_JNI_DESTROYJAVAVM_ENTRY( |
dcubed@3202 | 5244 | vm); |
dcubed@3202 | 5245 | #endif /* USDT2 */ |
duke@435 | 5246 | jint res = JNI_ERR; |
duke@435 | 5247 | DT_RETURN_MARK(DestroyJavaVM, jint, (const jint&)res); |
duke@435 | 5248 | |
duke@435 | 5249 | if (!vm_created) { |
duke@435 | 5250 | res = JNI_ERR; |
duke@435 | 5251 | return res; |
duke@435 | 5252 | } |
duke@435 | 5253 | |
duke@435 | 5254 | JNIWrapper("DestroyJavaVM"); |
duke@435 | 5255 | JNIEnv *env; |
duke@435 | 5256 | JavaVMAttachArgs destroyargs; |
duke@435 | 5257 | destroyargs.version = CurrentVersion; |
duke@435 | 5258 | destroyargs.name = (char *)"DestroyJavaVM"; |
duke@435 | 5259 | destroyargs.group = NULL; |
duke@435 | 5260 | res = vm->AttachCurrentThread((void **)&env, (void *)&destroyargs); |
duke@435 | 5261 | if (res != JNI_OK) { |
duke@435 | 5262 | return res; |
duke@435 | 5263 | } |
duke@435 | 5264 | |
duke@435 | 5265 | // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. |
duke@435 | 5266 | JavaThread* thread = JavaThread::current(); |
duke@435 | 5267 | ThreadStateTransition::transition_from_native(thread, _thread_in_vm); |
duke@435 | 5268 | if (Threads::destroy_vm()) { |
duke@435 | 5269 | // Should not change thread state, VM is gone |
duke@435 | 5270 | vm_created = false; |
duke@435 | 5271 | res = JNI_OK; |
duke@435 | 5272 | return res; |
duke@435 | 5273 | } else { |
duke@435 | 5274 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5275 | res = JNI_ERR; |
duke@435 | 5276 | return res; |
duke@435 | 5277 | } |
duke@435 | 5278 | } |
duke@435 | 5279 | |
duke@435 | 5280 | |
duke@435 | 5281 | static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool daemon) { |
duke@435 | 5282 | JavaVMAttachArgs *args = (JavaVMAttachArgs *) _args; |
duke@435 | 5283 | |
duke@435 | 5284 | // Check below commented out from JDK1.2fcs as well |
duke@435 | 5285 | /* |
duke@435 | 5286 | if (args && (args->version != JNI_VERSION_1_1 || args->version != JNI_VERSION_1_2)) { |
duke@435 | 5287 | return JNI_EVERSION; |
duke@435 | 5288 | } |
duke@435 | 5289 | */ |
duke@435 | 5290 | |
duke@435 | 5291 | Thread* t = ThreadLocalStorage::get_thread_slow(); |
duke@435 | 5292 | if (t != NULL) { |
duke@435 | 5293 | // If the thread has been attached this operation is a no-op |
duke@435 | 5294 | *(JNIEnv**)penv = ((JavaThread*) t)->jni_environment(); |
duke@435 | 5295 | return JNI_OK; |
duke@435 | 5296 | } |
duke@435 | 5297 | |
duke@435 | 5298 | // Create a thread and mark it as attaching so it will be skipped by the |
duke@435 | 5299 | // ThreadsListEnumerator - see CR 6404306 |
duke@435 | 5300 | JavaThread* thread = new JavaThread(true); |
duke@435 | 5301 | |
duke@435 | 5302 | // Set correct safepoint info. The thread is going to call into Java when |
duke@435 | 5303 | // initializing the Java level thread object. Hence, the correct state must |
duke@435 | 5304 | // be set in order for the Safepoint code to deal with it correctly. |
duke@435 | 5305 | thread->set_thread_state(_thread_in_vm); |
duke@435 | 5306 | // Must do this before initialize_thread_local_storage |
duke@435 | 5307 | thread->record_stack_base_and_size(); |
coleenp@1725 | 5308 | |
duke@435 | 5309 | thread->initialize_thread_local_storage(); |
duke@435 | 5310 | |
duke@435 | 5311 | if (!os::create_attached_thread(thread)) { |
duke@435 | 5312 | delete thread; |
duke@435 | 5313 | return JNI_ERR; |
duke@435 | 5314 | } |
coleenp@1725 | 5315 | // Enable stack overflow checks |
coleenp@1725 | 5316 | thread->create_stack_guard_pages(); |
coleenp@1725 | 5317 | |
duke@435 | 5318 | thread->initialize_tlab(); |
duke@435 | 5319 | |
bobv@2036 | 5320 | thread->cache_global_variables(); |
bobv@2036 | 5321 | |
duke@435 | 5322 | // Crucial that we do not have a safepoint check for this thread, since it has |
duke@435 | 5323 | // not been added to the Thread list yet. |
duke@435 | 5324 | { Threads_lock->lock_without_safepoint_check(); |
duke@435 | 5325 | // This must be inside this lock in order to get FullGCALot to work properly, i.e., to |
duke@435 | 5326 | // avoid this thread trying to do a GC before it is added to the thread-list |
duke@435 | 5327 | thread->set_active_handles(JNIHandleBlock::allocate_block()); |
duke@435 | 5328 | Threads::add(thread, daemon); |
duke@435 | 5329 | Threads_lock->unlock(); |
duke@435 | 5330 | } |
duke@435 | 5331 | // Create thread group and name info from attach arguments |
duke@435 | 5332 | oop group = NULL; |
duke@435 | 5333 | char* thread_name = NULL; |
duke@435 | 5334 | if (args != NULL && Threads::is_supported_jni_version(args->version)) { |
duke@435 | 5335 | group = JNIHandles::resolve(args->group); |
duke@435 | 5336 | thread_name = args->name; // may be NULL |
duke@435 | 5337 | } |
duke@435 | 5338 | if (group == NULL) group = Universe::main_thread_group(); |
duke@435 | 5339 | |
duke@435 | 5340 | // Create Java level thread object and attach it to this thread |
duke@435 | 5341 | bool attach_failed = false; |
duke@435 | 5342 | { |
duke@435 | 5343 | EXCEPTION_MARK; |
duke@435 | 5344 | HandleMark hm(THREAD); |
duke@435 | 5345 | Handle thread_group(THREAD, group); |
duke@435 | 5346 | thread->allocate_threadObj(thread_group, thread_name, daemon, THREAD); |
duke@435 | 5347 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 5348 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 5349 | // cleanup outside the handle mark. |
duke@435 | 5350 | attach_failed = true; |
duke@435 | 5351 | } |
duke@435 | 5352 | } |
duke@435 | 5353 | |
duke@435 | 5354 | if (attach_failed) { |
duke@435 | 5355 | // Added missing cleanup |
duke@435 | 5356 | thread->cleanup_failed_attach_current_thread(); |
duke@435 | 5357 | return JNI_ERR; |
duke@435 | 5358 | } |
duke@435 | 5359 | |
duke@435 | 5360 | // mark the thread as no longer attaching |
duke@435 | 5361 | // this uses a fence to push the change through so we don't have |
duke@435 | 5362 | // to regrab the threads_lock |
dcubed@3202 | 5363 | thread->set_done_attaching_via_jni(); |
duke@435 | 5364 | |
duke@435 | 5365 | // Set java thread status. |
duke@435 | 5366 | java_lang_Thread::set_thread_status(thread->threadObj(), |
duke@435 | 5367 | java_lang_Thread::RUNNABLE); |
duke@435 | 5368 | |
duke@435 | 5369 | // Notify the debugger |
duke@435 | 5370 | if (JvmtiExport::should_post_thread_life()) { |
duke@435 | 5371 | JvmtiExport::post_thread_start(thread); |
duke@435 | 5372 | } |
duke@435 | 5373 | |
sla@5237 | 5374 | EventThreadStart event; |
sla@5237 | 5375 | if (event.should_commit()) { |
sla@5237 | 5376 | event.set_javalangthread(java_lang_Thread::thread_id(thread->threadObj())); |
sla@5237 | 5377 | event.commit(); |
sla@5237 | 5378 | } |
phh@3427 | 5379 | |
duke@435 | 5380 | *(JNIEnv**)penv = thread->jni_environment(); |
duke@435 | 5381 | |
duke@435 | 5382 | // Now leaving the VM, so change thread_state. This is normally automatically taken care |
duke@435 | 5383 | // of in the JVM_ENTRY. But in this situation we have to do it manually. Notice, that by |
duke@435 | 5384 | // using ThreadStateTransition::transition, we do a callback to the safepoint code if |
duke@435 | 5385 | // needed. |
duke@435 | 5386 | |
duke@435 | 5387 | ThreadStateTransition::transition_and_fence(thread, _thread_in_vm, _thread_in_native); |
duke@435 | 5388 | |
duke@435 | 5389 | // Perform any platform dependent FPU setup |
duke@435 | 5390 | os::setup_fpu(); |
duke@435 | 5391 | |
duke@435 | 5392 | return JNI_OK; |
duke@435 | 5393 | } |
duke@435 | 5394 | |
duke@435 | 5395 | |
duke@435 | 5396 | jint JNICALL jni_AttachCurrentThread(JavaVM *vm, void **penv, void *_args) { |
dcubed@3202 | 5397 | #ifndef USDT2 |
duke@435 | 5398 | DTRACE_PROBE3(hotspot_jni, AttachCurrentThread__entry, vm, penv, _args); |
dcubed@3202 | 5399 | #else /* USDT2 */ |
dcubed@3202 | 5400 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_ENTRY( |
dcubed@3202 | 5401 | vm, penv, _args); |
dcubed@3202 | 5402 | #endif /* USDT2 */ |
duke@435 | 5403 | if (!vm_created) { |
dcubed@3202 | 5404 | #ifndef USDT2 |
duke@435 | 5405 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, JNI_ERR); |
dcubed@3202 | 5406 | #else /* USDT2 */ |
dcubed@3202 | 5407 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5408 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5409 | #endif /* USDT2 */ |
duke@435 | 5410 | return JNI_ERR; |
duke@435 | 5411 | } |
duke@435 | 5412 | |
duke@435 | 5413 | JNIWrapper("AttachCurrentThread"); |
duke@435 | 5414 | jint ret = attach_current_thread(vm, penv, _args, false); |
dcubed@3202 | 5415 | #ifndef USDT2 |
duke@435 | 5416 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThread__return, ret); |
dcubed@3202 | 5417 | #else /* USDT2 */ |
dcubed@3202 | 5418 | HOTSPOT_JNI_ATTACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5419 | ret); |
dcubed@3202 | 5420 | #endif /* USDT2 */ |
duke@435 | 5421 | return ret; |
duke@435 | 5422 | } |
duke@435 | 5423 | |
duke@435 | 5424 | |
duke@435 | 5425 | jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { |
dcubed@3202 | 5426 | #ifndef USDT2 |
duke@435 | 5427 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__entry, vm); |
dcubed@3202 | 5428 | #else /* USDT2 */ |
dcubed@3202 | 5429 | HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY( |
dcubed@3202 | 5430 | vm); |
dcubed@3202 | 5431 | #endif /* USDT2 */ |
duke@435 | 5432 | VM_Exit::block_if_vm_exited(); |
duke@435 | 5433 | |
duke@435 | 5434 | JNIWrapper("DetachCurrentThread"); |
duke@435 | 5435 | |
duke@435 | 5436 | // If the thread has been deattacted the operations is a no-op |
duke@435 | 5437 | if (ThreadLocalStorage::thread() == NULL) { |
dcubed@3202 | 5438 | #ifndef USDT2 |
duke@435 | 5439 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
dcubed@3202 | 5440 | #else /* USDT2 */ |
dcubed@3202 | 5441 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5442 | JNI_OK); |
dcubed@3202 | 5443 | #endif /* USDT2 */ |
duke@435 | 5444 | return JNI_OK; |
duke@435 | 5445 | } |
duke@435 | 5446 | |
duke@435 | 5447 | JavaThread* thread = JavaThread::current(); |
duke@435 | 5448 | if (thread->has_last_Java_frame()) { |
dcubed@3202 | 5449 | #ifndef USDT2 |
duke@435 | 5450 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_ERR); |
dcubed@3202 | 5451 | #else /* USDT2 */ |
dcubed@3202 | 5452 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5453 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5454 | #endif /* USDT2 */ |
duke@435 | 5455 | // Can't detach a thread that's running java, that can't work. |
duke@435 | 5456 | return JNI_ERR; |
duke@435 | 5457 | } |
duke@435 | 5458 | |
duke@435 | 5459 | // Safepoint support. Have to do call-back to safepoint code, if in the |
duke@435 | 5460 | // middel of a safepoint operation |
duke@435 | 5461 | ThreadStateTransition::transition_from_native(thread, _thread_in_vm); |
duke@435 | 5462 | |
duke@435 | 5463 | // XXX: Note that JavaThread::exit() call below removes the guards on the |
duke@435 | 5464 | // stack pages set up via enable_stack_{red,yellow}_zone() calls |
duke@435 | 5465 | // above in jni_AttachCurrentThread. Unfortunately, while the setting |
duke@435 | 5466 | // of the guards is visible in jni_AttachCurrentThread above, |
duke@435 | 5467 | // the removal of the guards is buried below in JavaThread::exit() |
duke@435 | 5468 | // here. The abstraction should be more symmetrically either exposed |
duke@435 | 5469 | // or hidden (e.g. it could probably be hidden in the same |
duke@435 | 5470 | // (platform-dependent) methods where we do alternate stack |
duke@435 | 5471 | // maintenance work?) |
duke@435 | 5472 | thread->exit(false, JavaThread::jni_detach); |
duke@435 | 5473 | delete thread; |
duke@435 | 5474 | |
dcubed@3202 | 5475 | #ifndef USDT2 |
duke@435 | 5476 | DTRACE_PROBE1(hotspot_jni, DetachCurrentThread__return, JNI_OK); |
dcubed@3202 | 5477 | #else /* USDT2 */ |
dcubed@3202 | 5478 | HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN( |
dcubed@3202 | 5479 | JNI_OK); |
dcubed@3202 | 5480 | #endif /* USDT2 */ |
duke@435 | 5481 | return JNI_OK; |
duke@435 | 5482 | } |
duke@435 | 5483 | |
dcubed@3202 | 5484 | #ifndef USDT2 |
duke@435 | 5485 | DT_RETURN_MARK_DECL(GetEnv, jint); |
dcubed@3202 | 5486 | #else /* USDT2 */ |
dcubed@3202 | 5487 | DT_RETURN_MARK_DECL(GetEnv, jint |
dcubed@3202 | 5488 | , HOTSPOT_JNI_GETENV_RETURN(_ret_ref)); |
dcubed@3202 | 5489 | #endif /* USDT2 */ |
duke@435 | 5490 | |
duke@435 | 5491 | jint JNICALL jni_GetEnv(JavaVM *vm, void **penv, jint version) { |
dcubed@3202 | 5492 | #ifndef USDT2 |
duke@435 | 5493 | DTRACE_PROBE3(hotspot_jni, GetEnv__entry, vm, penv, version); |
dcubed@3202 | 5494 | #else /* USDT2 */ |
dcubed@3202 | 5495 | HOTSPOT_JNI_GETENV_ENTRY( |
dcubed@3202 | 5496 | vm, penv, version); |
dcubed@3202 | 5497 | #endif /* USDT2 */ |
duke@435 | 5498 | jint ret = JNI_ERR; |
duke@435 | 5499 | DT_RETURN_MARK(GetEnv, jint, (const jint&)ret); |
duke@435 | 5500 | |
duke@435 | 5501 | if (!vm_created) { |
duke@435 | 5502 | *penv = NULL; |
duke@435 | 5503 | ret = JNI_EDETACHED; |
duke@435 | 5504 | return ret; |
duke@435 | 5505 | } |
duke@435 | 5506 | |
phh@3427 | 5507 | if (JniExportedInterface::GetExportedInterface(vm, penv, version, &ret)) { |
duke@435 | 5508 | return ret; |
duke@435 | 5509 | } |
duke@435 | 5510 | |
duke@435 | 5511 | #ifndef JVMPI_VERSION_1 |
duke@435 | 5512 | // need these in order to be polite about older agents |
duke@435 | 5513 | #define JVMPI_VERSION_1 ((jint)0x10000001) |
duke@435 | 5514 | #define JVMPI_VERSION_1_1 ((jint)0x10000002) |
duke@435 | 5515 | #define JVMPI_VERSION_1_2 ((jint)0x10000003) |
duke@435 | 5516 | #endif // !JVMPI_VERSION_1 |
duke@435 | 5517 | |
duke@435 | 5518 | Thread* thread = ThreadLocalStorage::thread(); |
duke@435 | 5519 | if (thread != NULL && thread->is_Java_thread()) { |
duke@435 | 5520 | if (Threads::is_supported_jni_version_including_1_1(version)) { |
duke@435 | 5521 | *(JNIEnv**)penv = ((JavaThread*) thread)->jni_environment(); |
duke@435 | 5522 | ret = JNI_OK; |
duke@435 | 5523 | return ret; |
duke@435 | 5524 | |
duke@435 | 5525 | } else if (version == JVMPI_VERSION_1 || |
duke@435 | 5526 | version == JVMPI_VERSION_1_1 || |
duke@435 | 5527 | version == JVMPI_VERSION_1_2) { |
duke@435 | 5528 | tty->print_cr("ERROR: JVMPI, an experimental interface, is no longer supported."); |
duke@435 | 5529 | tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); |
duke@435 | 5530 | ret = JNI_EVERSION; |
duke@435 | 5531 | return ret; |
duke@435 | 5532 | } else if (JvmtiExport::is_jvmdi_version(version)) { |
duke@435 | 5533 | tty->print_cr("FATAL ERROR: JVMDI is no longer supported."); |
duke@435 | 5534 | tty->print_cr("Please use the supported interface: the JVM Tool Interface (JVM TI)."); |
duke@435 | 5535 | ret = JNI_EVERSION; |
duke@435 | 5536 | return ret; |
duke@435 | 5537 | } else { |
duke@435 | 5538 | *penv = NULL; |
duke@435 | 5539 | ret = JNI_EVERSION; |
duke@435 | 5540 | return ret; |
duke@435 | 5541 | } |
duke@435 | 5542 | } else { |
duke@435 | 5543 | *penv = NULL; |
duke@435 | 5544 | ret = JNI_EDETACHED; |
duke@435 | 5545 | return ret; |
duke@435 | 5546 | } |
duke@435 | 5547 | } |
duke@435 | 5548 | |
duke@435 | 5549 | |
duke@435 | 5550 | jint JNICALL jni_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *_args) { |
dcubed@3202 | 5551 | #ifndef USDT2 |
duke@435 | 5552 | DTRACE_PROBE3(hotspot_jni, AttachCurrentThreadAsDaemon__entry, vm, penv, _args); |
dcubed@3202 | 5553 | #else /* USDT2 */ |
dcubed@3202 | 5554 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_ENTRY( |
dcubed@3202 | 5555 | vm, penv, _args); |
dcubed@3202 | 5556 | #endif /* USDT2 */ |
duke@435 | 5557 | if (!vm_created) { |
dcubed@3202 | 5558 | #ifndef USDT2 |
duke@435 | 5559 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, JNI_ERR); |
dcubed@3202 | 5560 | #else /* USDT2 */ |
dcubed@3202 | 5561 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( |
dcubed@3202 | 5562 | (uint32_t) JNI_ERR); |
dcubed@3202 | 5563 | #endif /* USDT2 */ |
duke@435 | 5564 | return JNI_ERR; |
duke@435 | 5565 | } |
duke@435 | 5566 | |
duke@435 | 5567 | JNIWrapper("AttachCurrentThreadAsDaemon"); |
duke@435 | 5568 | jint ret = attach_current_thread(vm, penv, _args, true); |
dcubed@3202 | 5569 | #ifndef USDT2 |
duke@435 | 5570 | DTRACE_PROBE1(hotspot_jni, AttachCurrentThreadAsDaemon__return, ret); |
dcubed@3202 | 5571 | #else /* USDT2 */ |
dcubed@3202 | 5572 | HOTSPOT_JNI_ATTACHCURRENTTHREADASDAEMON_RETURN( |
dcubed@3202 | 5573 | ret); |
dcubed@3202 | 5574 | #endif /* USDT2 */ |
duke@435 | 5575 | return ret; |
duke@435 | 5576 | } |
duke@435 | 5577 | |
duke@435 | 5578 | |
duke@435 | 5579 | } // End extern "C" |
duke@435 | 5580 | |
duke@435 | 5581 | const struct JNIInvokeInterface_ jni_InvokeInterface = { |
duke@435 | 5582 | NULL, |
duke@435 | 5583 | NULL, |
duke@435 | 5584 | NULL, |
duke@435 | 5585 | |
duke@435 | 5586 | jni_DestroyJavaVM, |
duke@435 | 5587 | jni_AttachCurrentThread, |
duke@435 | 5588 | jni_DetachCurrentThread, |
duke@435 | 5589 | jni_GetEnv, |
duke@435 | 5590 | jni_AttachCurrentThreadAsDaemon |
duke@435 | 5591 | }; |