* src/vm/primitive.c (primitive_type_get_by_wrapperclass): New
authortwisti <none@none>
Thu, 16 Aug 2007 17:52:48 +0000 (17:52 +0000)
committertwisti <none@none>
Thu, 16 Aug 2007 17:52:48 +0000 (17:52 +0000)
function.
(primitive_unbox): Changed signature.
* src/vm/primitive.h: Likewise.

* src/vm/vm.c (vm_array_from_objectarray): Rewritten to use
primitive-unbox function.

src/vm/primitive.c
src/vm/primitive.h
src/vm/vm.c

index 93eac1d737b8848e2019057cd2c7891b0496daa9..81a0d34fcce5f6406d8312d222c70e0f0f0b54bb 100644 (file)
@@ -168,6 +168,28 @@ classinfo *primitive_arrayclass_get_by_type(int type)
 }
 
 
+/* primitive_type_get_by_wrapperclass ******************************************
+
+   Returns the primitive type of the given wrapper-class.
+
+*******************************************************************************/
+
+int primitive_type_get_by_wrapperclass(classinfo *c)
+{
+       int i;
+
+       /* Search primitive table. */
+
+       for (i = 0; i < PRIMITIVETYPE_COUNT; i++)
+               if (primitivetype_table[i].class_wrap == c)
+                       return i;
+
+       /* Invalid primitive wrapper-class. */
+
+       return -1;
+}
+
+
 /* primitive_box ***************************************************************
 
    Box a primitive of the given type.
@@ -217,9 +239,15 @@ java_handle_t *primitive_box(int type, imm_union value)
 
 *******************************************************************************/
 
-imm_union primitive_unbox(int type, java_handle_t *o)
+imm_union primitive_unbox(java_handle_t *o)
 {
-       imm_union value;
+       classinfo *c;
+       int        type;
+       imm_union  value;
+
+       c = o->vftbl->class;
+
+       type = primitive_type_get_by_wrapperclass(c);
 
        switch (type) {
        case PRIMITIVETYPE_BOOLEAN:
index 5695f8fdde78a59e26911140be24b3f06700dfd5..8b506cb2c736d823808af4adfd5efe0dcf9457aa 100644 (file)
@@ -110,11 +110,14 @@ bool       primitive_init(void);
 classinfo *primitive_class_get_by_name(utf *name);
 classinfo *primitive_class_get_by_type(int type);
 classinfo *primitive_class_get_by_char(char ch);
+
 classinfo *primitive_arrayclass_get_by_name(utf *name);
 classinfo *primitive_arrayclass_get_by_type(int type);
 
+int        primitive_type_get_by_wrapperclass(classinfo *c);
+
 java_handle_t *primitive_box(int type, imm_union value);
-imm_union      primitive_unbox(int type, java_handle_t *o);
+imm_union      primitive_unbox(java_handle_t *o);
 
 java_handle_t *primitive_box_boolean(int32_t value);
 java_handle_t *primitive_box_byte(int32_t value);
index 6269db5a5320953216f16c03ea51b5856caf581f..c0b2ea7db07a5654a520dad3e28a7ff79dd4ad4c 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: vm.c 8318 2007-08-16 10:05:34Z michi $
+   $Id: vm.c 8327 2007-08-16 17:52:48Z twisti $
 
 */
 
@@ -2716,6 +2716,7 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
        uint64_t      *array;
        java_handle_t *param;
        classinfo     *c;
+       int            type;
        int32_t        i;
        int32_t        j;
        imm_union      value;
@@ -2753,54 +2754,69 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
 
                        /* convert the value according to its declared type */
 
-                       c = param->vftbl->class;
+                       c    = param->vftbl->class;
+                       type = primitive_type_get_by_wrapperclass(c);
 
                        switch (td->decltype) {
                        case PRIMITIVETYPE_BOOLEAN:
-                               if (c == class_java_lang_Boolean)
-                                       LLNI_field_get_val((java_lang_Boolean *) param, value, value.i);
-                               else
+                               switch (type) {
+                               case PRIMITIVETYPE_BOOLEAN:
+                                       /* This type is OK. */
+                                       break;
+                               default:
                                        goto illegal_arg;
+                               }
                                break;
 
                        case PRIMITIVETYPE_BYTE:
-                               if (c == class_java_lang_Byte)
-                                       LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
-                               else
+                               switch (type) {
+                               case PRIMITIVETYPE_BYTE:
+                                       /* This type is OK. */
+                                       break;
+                               default:
                                        goto illegal_arg;
+                               }
                                break;
 
                        case PRIMITIVETYPE_CHAR:
-                               if (c == class_java_lang_Character)
-                                       LLNI_field_get_val((java_lang_Character *) param, value, value.i);
-                               else
+                               switch (type) {
+                               case PRIMITIVETYPE_CHAR:
+                                       /* This type is OK. */
+                                       break;
+                               default:
                                        goto illegal_arg;
+                               }
                                break;
 
                        case PRIMITIVETYPE_SHORT:
-                               if (c == class_java_lang_Short)
-                                       LLNI_field_get_val((java_lang_Short *) param, value, value.i);
-                               else if (c == class_java_lang_Byte)
-                                       LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
-                               else
+                               switch (type) {
+                               case PRIMITIVETYPE_BYTE:
+                               case PRIMITIVETYPE_SHORT:
+                                       /* These types are OK. */
+                                       break;
+                               default:
                                        goto illegal_arg;
+                               }
                                break;
 
                        case PRIMITIVETYPE_INT:
-                               if (c == class_java_lang_Integer)
-                                       LLNI_field_get_val((java_lang_Integer *) param, value, value.i);
-                               else if (c == class_java_lang_Short)
-                                       LLNI_field_get_val((java_lang_Short *) param, value, value.i);
-                               else if (c == class_java_lang_Byte)
-                                       LLNI_field_get_val((java_lang_Byte *) param, value, value.i);
-                               else
+                               switch (type) {
+                               case PRIMITIVETYPE_BYTE:
+                               case PRIMITIVETYPE_SHORT:
+                               case PRIMITIVETYPE_INT:
+                                       /* These types are OK. */
+                                       break;
+                               default:
                                        goto illegal_arg;
+                               }
                                break;
 
                        default:
-                               goto illegal_arg;
+                               vm_abort("vm_array_from_objectarray: invalid type %d",
+                                                td->decltype);
                        }
 
+                       value = primitive_unbox(param);
                        vm_array_store_int(array, pd, value.i);
                        break;
 
@@ -2808,28 +2824,24 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
                        if (param == NULL)
                                goto illegal_arg;
 
-                       /* convert the value according to its declared type */
+                       c    = param->vftbl->class;
+                       type = primitive_type_get_by_class(c);
 
-                       c = param->vftbl->class;
+                       assert(td->decltype == PRIMITIVETYPE_LONG);
 
-                       switch (td->decltype) {
+                       switch (type) {
+                       case PRIMITIVETYPE_BYTE:
+                       case PRIMITIVETYPE_SHORT:
+                       case PRIMITIVETYPE_INT:
                        case PRIMITIVETYPE_LONG:
-                               if (c == class_java_lang_Long)
-                                       LLNI_field_get_val((java_lang_Long *) param, value, value.l);
-                               else if (c == class_java_lang_Integer)
-                                       value.l = (int64_t) LLNI_field_direct(((java_lang_Integer *) param), value);
-                               else if (c == class_java_lang_Short)
-                                       value.l = (int64_t) LLNI_field_direct(((java_lang_Short *) param), value);
-                               else if (c == class_java_lang_Byte)
-                                       value.l = (int64_t) LLNI_field_direct(((java_lang_Byte *) param), value);
-                               else
-                                       goto illegal_arg;
+                               /* These types are OK. */
                                break;
-
                        default:
                                goto illegal_arg;
                        }
 
+                       log_println("TRACE 2");
+                       value = primitive_unbox(param);
                        vm_array_store_lng(array, pd, value.l);
                        break;
 
@@ -2837,22 +2849,21 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
                        if (param == NULL)
                                goto illegal_arg;
 
-                       /* convert the value according to its declared type */
+                       c    = param->vftbl->class;
+                       type = primitive_type_get_by_class(c);
 
-                       c = param->vftbl->class;
+                       assert(td->decltype == PRIMITIVETYPE_FLOAT);
 
-                       switch (td->decltype) {
+                       switch (type) {
                        case PRIMITIVETYPE_FLOAT:
-                               if (c == class_java_lang_Float)
-                                       LLNI_field_get_val((java_lang_Float *) param, value, value.f);
-                               else
-                                       goto illegal_arg;
+                               /* This type is OK. */
                                break;
-
                        default:
                                goto illegal_arg;
                        }
 
+                       log_println("TRACE 3");
+                       value = primitive_unbox(param);
                        vm_array_store_flt(array, pd, value.l);
                        break;
 
@@ -2860,24 +2871,22 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
                        if (param == NULL)
                                goto illegal_arg;
 
-                       /* convert the value according to its declared type */
+                       c    = param->vftbl->class;
+                       type = primitive_type_get_by_class(c);
 
-                       c = param->vftbl->class;
+                       assert(td->decltype == PRIMITIVETYPE_DOUBLE);
 
-                       switch (td->decltype) {
+                       switch (type) {
+                       case PRIMITIVETYPE_FLOAT:
                        case PRIMITIVETYPE_DOUBLE:
-                               if (c == class_java_lang_Double)
-                                       LLNI_field_get_val((java_lang_Double *) param, value, value.d);
-                               else if (c == class_java_lang_Float)
-                                       LLNI_field_get_val((java_lang_Float *) param, value, value.f);
-                               else
-                                       goto illegal_arg;
+                               /* These types are OK. */
                                break;
-
                        default:
                                goto illegal_arg;
                        }
 
+                       log_println("TRACE 4");
+                       value = primitive_unbox(param);
                        vm_array_store_dbl(array, pd, value.l);
                        break;
                
@@ -2900,7 +2909,7 @@ uint64_t *vm_array_from_objectarray(methodinfo *m, java_object_t *o,
                        break;
 
                default:
-                       goto illegal_arg;
+                       vm_abort("vm_array_from_objectarray: invalid type %d", td->type);
                }
        }