< prev index next >

src/share/vm/runtime/reflection.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1076   JavaValue result(rtype);
1077   JavaCalls::call(&result, method, &java_args, THREAD);
1078 
1079   if (HAS_PENDING_EXCEPTION) {
1080     // Method threw an exception; wrap it in an InvocationTargetException
1081     oop target_exception = PENDING_EXCEPTION;
1082     CLEAR_PENDING_EXCEPTION;
1083     // JVMTI has already reported the pending exception
1084     // JVMTI internal flag reset is needed in order to report InvocationTargetException
1085     if (THREAD->is_Java_thread()) {
1086       JvmtiExport::clear_detected_exception((JavaThread*) THREAD);
1087     }
1088 
1089     JavaCallArguments args(Handle(THREAD, target_exception));
1090     THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(),
1091                 vmSymbols::throwable_void_signature(),
1092                 &args);
1093   } else {
1094     if (rtype == T_BOOLEAN || rtype == T_BYTE || rtype == T_CHAR || rtype == T_SHORT)
1095       narrow((jvalue*) result.get_value_addr(), rtype, CHECK_NULL);
1096     return box((jvalue*) result.get_value_addr(), rtype, CHECK_NULL);
1097   }
1098 }
1099 
1100 
1101 void Reflection::narrow(jvalue* value, BasicType narrow_type, TRAPS) {
1102   switch (narrow_type) {
1103     case T_BOOLEAN:
1104      value->z = (jboolean) (value->i & 1);
1105      return;
1106     case T_BYTE:
1107      value->b = (jbyte) value->i;
1108      return;
1109     case T_CHAR:
1110      value->c = (jchar) value->i;
1111      return;
1112     case T_SHORT:
1113      value->s = (jshort) value->i;
1114      return;
1115     default:
1116       break; // fail


   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1076   JavaValue result(rtype);
1077   JavaCalls::call(&result, method, &java_args, THREAD);
1078 
1079   if (HAS_PENDING_EXCEPTION) {
1080     // Method threw an exception; wrap it in an InvocationTargetException
1081     oop target_exception = PENDING_EXCEPTION;
1082     CLEAR_PENDING_EXCEPTION;
1083     // JVMTI has already reported the pending exception
1084     // JVMTI internal flag reset is needed in order to report InvocationTargetException
1085     if (THREAD->is_Java_thread()) {
1086       JvmtiExport::clear_detected_exception((JavaThread*) THREAD);
1087     }
1088 
1089     JavaCallArguments args(Handle(THREAD, target_exception));
1090     THROW_ARG_0(vmSymbols::java_lang_reflect_InvocationTargetException(),
1091                 vmSymbols::throwable_void_signature(),
1092                 &args);
1093   } else {
1094     if (rtype == T_BOOLEAN || rtype == T_BYTE || rtype == T_CHAR || rtype == T_SHORT)
1095       narrow((jvalue*) result.get_value_addr(), rtype, CHECK_NULL);
1096     return box((jvalue*) result.get_value_addr(), rtype, THREAD);
1097   }
1098 }
1099 
1100 
1101 void Reflection::narrow(jvalue* value, BasicType narrow_type, TRAPS) {
1102   switch (narrow_type) {
1103     case T_BOOLEAN:
1104      value->z = (jboolean) (value->i & 1);
1105      return;
1106     case T_BYTE:
1107      value->b = (jbyte) value->i;
1108      return;
1109     case T_CHAR:
1110      value->c = (jchar) value->i;
1111      return;
1112     case T_SHORT:
1113      value->s = (jshort) value->i;
1114      return;
1115     default:
1116       break; // fail


< prev index next >