< prev index next >

src/share/vm/runtime/reflection.cpp

Print this page




 109 
 110 BasicType Reflection::unbox_for_regular_object(oop box, jvalue* value) {
 111   // Note:  box is really the unboxed oop.  It might even be a Short, etc.!
 112   value->l = (jobject) box;
 113   return T_OBJECT;
 114 }
 115 
 116 
 117 void Reflection::widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS) {
 118   assert(wide_type != current_type, "widen should not be called with identical types");
 119   switch (wide_type) {
 120     case T_BOOLEAN:
 121     case T_BYTE:
 122     case T_CHAR:
 123       break;  // fail
 124     case T_SHORT:
 125       switch (current_type) {
 126         case T_BYTE:
 127           value->s = (jshort) value->b;
 128           return;


 129       }
 130       break;  // fail
 131     case T_INT:
 132       switch (current_type) {
 133         case T_BYTE:
 134           value->i = (jint) value->b;
 135           return;
 136         case T_CHAR:
 137           value->i = (jint) value->c;
 138           return;
 139         case T_SHORT:
 140           value->i = (jint) value->s;
 141           return;


 142       }
 143       break;  // fail
 144     case T_LONG:
 145       switch (current_type) {
 146         case T_BYTE:
 147           value->j = (jlong) value->b;
 148           return;
 149         case T_CHAR:
 150           value->j = (jlong) value->c;
 151           return;
 152         case T_SHORT:
 153           value->j = (jlong) value->s;
 154           return;
 155         case T_INT:
 156           value->j = (jlong) value->i;
 157           return;


 158       }
 159       break;  // fail
 160     case T_FLOAT:
 161       switch (current_type) {
 162         case T_BYTE:
 163           value->f = (jfloat) value->b;
 164           return;
 165         case T_CHAR:
 166           value->f = (jfloat) value->c;
 167           return;
 168         case T_SHORT:
 169           value->f = (jfloat) value->s;
 170           return;
 171         case T_INT:
 172           value->f = (jfloat) value->i;
 173           return;
 174         case T_LONG:
 175           value->f = (jfloat) value->j;
 176           return;


 177       }
 178       break;  // fail
 179     case T_DOUBLE:
 180       switch (current_type) {
 181         case T_BYTE:
 182           value->d = (jdouble) value->b;
 183           return;
 184         case T_CHAR:
 185           value->d = (jdouble) value->c;
 186           return;
 187         case T_SHORT:
 188           value->d = (jdouble) value->s;
 189           return;
 190         case T_INT:
 191           value->d = (jdouble) value->i;
 192           return;
 193         case T_FLOAT:
 194           value->d = (jdouble) value->f;
 195           return;
 196         case T_LONG:
 197           value->d = (jdouble) value->j;
 198           return;


 199       }
 200       break;  // fail
 201     default:
 202       break;  // fail
 203   }
 204   THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch");
 205 }
 206 
 207 
 208 BasicType Reflection::array_get(jvalue* value, arrayOop a, int index, TRAPS) {
 209   if (!a->is_within_bounds(index)) {
 210     THROW_(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), T_ILLEGAL);
 211   }
 212   if (a->is_objArray()) {
 213     value->l = (jobject) objArrayOop(a)->obj_at(index);
 214     return T_OBJECT;
 215   } else {
 216     assert(a->is_typeArray(), "just checking");
 217     BasicType type = TypeArrayKlass::cast(a->klass())->element_type();
 218     switch (type) {




 109 
 110 BasicType Reflection::unbox_for_regular_object(oop box, jvalue* value) {
 111   // Note:  box is really the unboxed oop.  It might even be a Short, etc.!
 112   value->l = (jobject) box;
 113   return T_OBJECT;
 114 }
 115 
 116 
 117 void Reflection::widen(jvalue* value, BasicType current_type, BasicType wide_type, TRAPS) {
 118   assert(wide_type != current_type, "widen should not be called with identical types");
 119   switch (wide_type) {
 120     case T_BOOLEAN:
 121     case T_BYTE:
 122     case T_CHAR:
 123       break;  // fail
 124     case T_SHORT:
 125       switch (current_type) {
 126         case T_BYTE:
 127           value->s = (jshort) value->b;
 128           return;
 129         default:
 130           break;
 131       }
 132       break;  // fail
 133     case T_INT:
 134       switch (current_type) {
 135         case T_BYTE:
 136           value->i = (jint) value->b;
 137           return;
 138         case T_CHAR:
 139           value->i = (jint) value->c;
 140           return;
 141         case T_SHORT:
 142           value->i = (jint) value->s;
 143           return;
 144         default:
 145           break;
 146       }
 147       break;  // fail
 148     case T_LONG:
 149       switch (current_type) {
 150         case T_BYTE:
 151           value->j = (jlong) value->b;
 152           return;
 153         case T_CHAR:
 154           value->j = (jlong) value->c;
 155           return;
 156         case T_SHORT:
 157           value->j = (jlong) value->s;
 158           return;
 159         case T_INT:
 160           value->j = (jlong) value->i;
 161           return;
 162         default:
 163           break;
 164       }
 165       break;  // fail
 166     case T_FLOAT:
 167       switch (current_type) {
 168         case T_BYTE:
 169           value->f = (jfloat) value->b;
 170           return;
 171         case T_CHAR:
 172           value->f = (jfloat) value->c;
 173           return;
 174         case T_SHORT:
 175           value->f = (jfloat) value->s;
 176           return;
 177         case T_INT:
 178           value->f = (jfloat) value->i;
 179           return;
 180         case T_LONG:
 181           value->f = (jfloat) value->j;
 182           return;
 183         default:
 184           break;
 185       }
 186       break;  // fail
 187     case T_DOUBLE:
 188       switch (current_type) {
 189         case T_BYTE:
 190           value->d = (jdouble) value->b;
 191           return;
 192         case T_CHAR:
 193           value->d = (jdouble) value->c;
 194           return;
 195         case T_SHORT:
 196           value->d = (jdouble) value->s;
 197           return;
 198         case T_INT:
 199           value->d = (jdouble) value->i;
 200           return;
 201         case T_FLOAT:
 202           value->d = (jdouble) value->f;
 203           return;
 204         case T_LONG:
 205           value->d = (jdouble) value->j;
 206           return;
 207         default:
 208           break;
 209       }
 210       break;  // fail
 211     default:
 212       break;  // fail
 213   }
 214   THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "argument type mismatch");
 215 }
 216 
 217 
 218 BasicType Reflection::array_get(jvalue* value, arrayOop a, int index, TRAPS) {
 219   if (!a->is_within_bounds(index)) {
 220     THROW_(vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), T_ILLEGAL);
 221   }
 222   if (a->is_objArray()) {
 223     value->l = (jobject) objArrayOop(a)->obj_at(index);
 224     return T_OBJECT;
 225   } else {
 226     assert(a->is_typeArray(), "just checking");
 227     BasicType type = TypeArrayKlass::cast(a->klass())->element_type();
 228     switch (type) {


< prev index next >