1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2012 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
692 #ifndef USDT2
693 DT_RETURN_MARK_DECL(Throw, jint);
694 #else /* USDT2 */
695 DT_RETURN_MARK_DECL(Throw, jint
696 , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
697 #endif /* USDT2 */
698
699 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
700 JNIWrapper("Throw");
701 #ifndef USDT2
702 DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj);
703 #else /* USDT2 */
704 HOTSPOT_JNI_THROW_ENTRY(
705 env, obj);
706 #endif /* USDT2 */
707 jint ret = JNI_OK;
708 DT_RETURN_MARK(Throw, jint, (const jint&)ret);
709
710 THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
711 ShouldNotReachHere();
712 JNI_END
713
714 #ifndef USDT2
715 DT_RETURN_MARK_DECL(ThrowNew, jint);
716 #else /* USDT2 */
717 DT_RETURN_MARK_DECL(ThrowNew, jint
718 , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
719 #endif /* USDT2 */
720
721 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
722 JNIWrapper("ThrowNew");
723 #ifndef USDT2
724 DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message);
725 #else /* USDT2 */
726 HOTSPOT_JNI_THROWNEW_ENTRY(
727 env, clazz, (char *) message);
728 #endif /* USDT2 */
729 jint ret = JNI_OK;
730 DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
731
732 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
733 Symbol* name = k->name();
734 Handle class_loader (THREAD, k->class_loader());
735 Handle protection_domain (THREAD, k->protection_domain());
736 THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
737 ShouldNotReachHere();
738 JNI_END
739
740
741 // JNI functions only transform a pending async exception to a synchronous
742 // exception in ExceptionOccurred and ExceptionCheck calls, since
743 // delivering an async exception in other places won't change the native
744 // code's control flow and would be harmful when native code further calls
745 // JNI functions with a pending exception. Async exception is also checked
746 // during the call, so ExceptionOccurred/ExceptionCheck won't return
747 // false but deliver the async exception at the very end during
748 // state transition.
749
750 static void jni_check_async_exceptions(JavaThread *thread) {
751 assert(thread == Thread::current(), "must be itself");
752 thread->check_and_handle_async_exceptions();
753 }
754
755 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
756 JNIWrapper("ExceptionOccurred");
757 #ifndef USDT2
1123 va_list _ap;
1124
1125 inline void get_bool() {
1126 // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1127 // 0 to JNI_FALSE. Boolean return values from native are normalized the same in
1128 // TemplateInterpreterGenerator::generate_result_handler_for and
1129 // SharedRuntime::generate_native_wrapper.
1130 jboolean b = va_arg(_ap, jint);
1131 _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1132 }
1133 inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg
1134 inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg
1135 inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg
1136 inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); }
1137
1138 // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
1139
1140 inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); }
1141 inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg
1142 inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); }
1143 inline void get_object() { jobject l = va_arg(_ap, jobject);
1144 _arguments->push_oop(Handle((oop *)l, false)); }
1145
1146 inline void set_ap(va_list rap) {
1147 #ifdef va_copy
1148 va_copy(_ap, rap);
1149 #elif defined (__va_copy)
1150 __va_copy(_ap, rap);
1151 #else
1152 _ap = rap;
1153 #endif
1154 }
1155
1156 public:
1157 JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap)
1158 : JNI_ArgumentPusher(signature) {
1159 set_ap(rap);
1160 }
1161 JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
1162 : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1163 set_ap(rap);
1164 }
1218 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher {
1219 protected:
1220 const jvalue *_ap;
1221
1222 inline void get_bool() {
1223 // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1224 // 0 to JNI_FALSE. Boolean return values from native are normalized the same in
1225 // TemplateInterpreterGenerator::generate_result_handler_for and
1226 // SharedRuntime::generate_native_wrapper.
1227 jboolean b = (_ap++)->z;
1228 _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1229 }
1230 inline void get_char() { _arguments->push_int((jint)(_ap++)->c); }
1231 inline void get_short() { _arguments->push_int((jint)(_ap++)->s); }
1232 inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); }
1233 inline void get_int() { _arguments->push_int((jint)(_ap++)->i); }
1234
1235 inline void get_long() { _arguments->push_long((_ap++)->j); }
1236 inline void get_float() { _arguments->push_float((_ap++)->f); }
1237 inline void get_double() { _arguments->push_double((_ap++)->d);}
1238 inline void get_object() { _arguments->push_oop(Handle((oop *)(_ap++)->l, false)); }
1239
1240 inline void set_ap(const jvalue *rap) { _ap = rap; }
1241
1242 public:
1243 JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap)
1244 : JNI_ArgumentPusher(signature) {
1245 set_ap(rap);
1246 }
1247 JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap)
1248 : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1249 set_ap(rap);
1250 }
1251
1252 // Optimized path if we have the bitvector form of signature
1253 void iterate( uint64_t fingerprint ) {
1254 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments
1255 else {
1256 _return_type = (BasicType)((fingerprint >> static_feature_size) &
1257 result_feature_mask);
1258 assert(fingerprint, "Fingerprint should not be 0");
|
1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2012 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
692 #ifndef USDT2
693 DT_RETURN_MARK_DECL(Throw, jint);
694 #else /* USDT2 */
695 DT_RETURN_MARK_DECL(Throw, jint
696 , HOTSPOT_JNI_THROW_RETURN(_ret_ref));
697 #endif /* USDT2 */
698
699 JNI_ENTRY(jint, jni_Throw(JNIEnv *env, jthrowable obj))
700 JNIWrapper("Throw");
701 #ifndef USDT2
702 DTRACE_PROBE2(hotspot_jni, Throw__entry, env, obj);
703 #else /* USDT2 */
704 HOTSPOT_JNI_THROW_ENTRY(
705 env, obj);
706 #endif /* USDT2 */
707 jint ret = JNI_OK;
708 DT_RETURN_MARK(Throw, jint, (const jint&)ret);
709
710 THROW_OOP_(JNIHandles::resolve(obj), JNI_OK);
711 ShouldNotReachHere();
712 return 0; // Mute compiler.
713 JNI_END
714
715 #ifndef USDT2
716 DT_RETURN_MARK_DECL(ThrowNew, jint);
717 #else /* USDT2 */
718 DT_RETURN_MARK_DECL(ThrowNew, jint
719 , HOTSPOT_JNI_THROWNEW_RETURN(_ret_ref));
720 #endif /* USDT2 */
721
722 JNI_ENTRY(jint, jni_ThrowNew(JNIEnv *env, jclass clazz, const char *message))
723 JNIWrapper("ThrowNew");
724 #ifndef USDT2
725 DTRACE_PROBE3(hotspot_jni, ThrowNew__entry, env, clazz, message);
726 #else /* USDT2 */
727 HOTSPOT_JNI_THROWNEW_ENTRY(
728 env, clazz, (char *) message);
729 #endif /* USDT2 */
730 jint ret = JNI_OK;
731 DT_RETURN_MARK(ThrowNew, jint, (const jint&)ret);
732
733 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
734 Symbol* name = k->name();
735 Handle class_loader (THREAD, k->class_loader());
736 Handle protection_domain (THREAD, k->protection_domain());
737 THROW_MSG_LOADER_(name, (char *)message, class_loader, protection_domain, JNI_OK);
738 ShouldNotReachHere();
739 return 0; // Mute compiler.
740 JNI_END
741
742
743 // JNI functions only transform a pending async exception to a synchronous
744 // exception in ExceptionOccurred and ExceptionCheck calls, since
745 // delivering an async exception in other places won't change the native
746 // code's control flow and would be harmful when native code further calls
747 // JNI functions with a pending exception. Async exception is also checked
748 // during the call, so ExceptionOccurred/ExceptionCheck won't return
749 // false but deliver the async exception at the very end during
750 // state transition.
751
752 static void jni_check_async_exceptions(JavaThread *thread) {
753 assert(thread == Thread::current(), "must be itself");
754 thread->check_and_handle_async_exceptions();
755 }
756
757 JNI_ENTRY_NO_PRESERVE(jthrowable, jni_ExceptionOccurred(JNIEnv *env))
758 JNIWrapper("ExceptionOccurred");
759 #ifndef USDT2
1125 va_list _ap;
1126
1127 inline void get_bool() {
1128 // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1129 // 0 to JNI_FALSE. Boolean return values from native are normalized the same in
1130 // TemplateInterpreterGenerator::generate_result_handler_for and
1131 // SharedRuntime::generate_native_wrapper.
1132 jboolean b = va_arg(_ap, jint);
1133 _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1134 }
1135 inline void get_char() { _arguments->push_int(va_arg(_ap, jint)); } // char is coerced to int when using va_arg
1136 inline void get_short() { _arguments->push_int(va_arg(_ap, jint)); } // short is coerced to int when using va_arg
1137 inline void get_byte() { _arguments->push_int(va_arg(_ap, jint)); } // byte is coerced to int when using va_arg
1138 inline void get_int() { _arguments->push_int(va_arg(_ap, jint)); }
1139
1140 // each of these paths is exercized by the various jck Call[Static,Nonvirtual,][Void,Int,..]Method[A,V,] tests
1141
1142 inline void get_long() { _arguments->push_long(va_arg(_ap, jlong)); }
1143 inline void get_float() { _arguments->push_float((jfloat)va_arg(_ap, jdouble)); } // float is coerced to double w/ va_arg
1144 inline void get_double() { _arguments->push_double(va_arg(_ap, jdouble)); }
1145 inline void get_object() { _arguments->push_jobject(va_arg(_ap, jobject)); }
1146
1147 inline void set_ap(va_list rap) {
1148 #ifdef va_copy
1149 va_copy(_ap, rap);
1150 #elif defined (__va_copy)
1151 __va_copy(_ap, rap);
1152 #else
1153 _ap = rap;
1154 #endif
1155 }
1156
1157 public:
1158 JNI_ArgumentPusherVaArg(Symbol* signature, va_list rap)
1159 : JNI_ArgumentPusher(signature) {
1160 set_ap(rap);
1161 }
1162 JNI_ArgumentPusherVaArg(jmethodID method_id, va_list rap)
1163 : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1164 set_ap(rap);
1165 }
1219 class JNI_ArgumentPusherArray : public JNI_ArgumentPusher {
1220 protected:
1221 const jvalue *_ap;
1222
1223 inline void get_bool() {
1224 // Normalize boolean arguments from native code by converting 1-255 to JNI_TRUE and
1225 // 0 to JNI_FALSE. Boolean return values from native are normalized the same in
1226 // TemplateInterpreterGenerator::generate_result_handler_for and
1227 // SharedRuntime::generate_native_wrapper.
1228 jboolean b = (_ap++)->z;
1229 _arguments->push_int((jint)(b == 0 ? JNI_FALSE : JNI_TRUE));
1230 }
1231 inline void get_char() { _arguments->push_int((jint)(_ap++)->c); }
1232 inline void get_short() { _arguments->push_int((jint)(_ap++)->s); }
1233 inline void get_byte() { _arguments->push_int((jint)(_ap++)->b); }
1234 inline void get_int() { _arguments->push_int((jint)(_ap++)->i); }
1235
1236 inline void get_long() { _arguments->push_long((_ap++)->j); }
1237 inline void get_float() { _arguments->push_float((_ap++)->f); }
1238 inline void get_double() { _arguments->push_double((_ap++)->d);}
1239 inline void get_object() { _arguments->push_jobject((_ap++)->l); }
1240
1241 inline void set_ap(const jvalue *rap) { _ap = rap; }
1242
1243 public:
1244 JNI_ArgumentPusherArray(Symbol* signature, const jvalue *rap)
1245 : JNI_ArgumentPusher(signature) {
1246 set_ap(rap);
1247 }
1248 JNI_ArgumentPusherArray(jmethodID method_id, const jvalue *rap)
1249 : JNI_ArgumentPusher(Method::resolve_jmethod_id(method_id)->signature()) {
1250 set_ap(rap);
1251 }
1252
1253 // Optimized path if we have the bitvector form of signature
1254 void iterate( uint64_t fingerprint ) {
1255 if ( fingerprint == UCONST64(-1) ) SignatureIterator::iterate(); // Must be too many arguments
1256 else {
1257 _return_type = (BasicType)((fingerprint >> static_feature_size) &
1258 result_feature_mask);
1259 assert(fingerprint, "Fingerprint should not be 0");
|