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