wei-spring / codenameone

Automatically exported from code.google.com/p/codenameone
0 stars 0 forks source link

NewVM: EXC_BAD_ACCESS in new Integer(int) #1311

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is part of tracking down crashes in the DataMapper library.  I'll be 
posting a more minimal case when I have narrowed it down.  Crash occurs here:

void set_field_java_lang_Integer_value(CODENAME_ONE_THREAD_STATE, JAVA_INT 
__cn1Val, JAVA_OBJECT __cn1T) {
    (*(struct obj__java_lang_Integer*)__cn1T).java_lang_Integer_value = __cn1Val;
}

EXC_BAD_ACCESS (code=1, address=0x19)

__cn1Val    JAVA_INT    16  16
__cn1T  JAVA_OBJECT 0x1 0x00000001

#0  0x00fc55ce in set_field_java_lang_Integer_value at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/java_lang_Integer.m:37
#1  0x00fc5896 in java_lang_Integer___INIT_____int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/java_lang_Integer.m:77
#2  0x011d375b in 
nl_synobsys_bowlingscore_mirah_FrameMapper_writeMap___java_util_Map_java_lang_Ob
ject at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/nl_synobsys_bowlingscore_mirah_FrameMapper.m:425
#3  0x00071498 in 
virtual_ca_weblite_codename1_mapper_DataMapper_writeMap___java_util_Map_java_lan
g_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3470
#4  0x0007002d in 
ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java_lang_Ob
ject at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:2122
#5  0x00071257 in 
virtual_ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3318
#6  0x0006e1b6 in 
ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java_lang_Ob
ject at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:1959
#7  0x00071257 in 
virtual_ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3318
#8  0x00071bc8 in 
ca_weblite_codename1_mapper_DataMapper_set___java_util_Map_java_lang_String_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:2272
#9  0x0007af43 in 
virtual_ca_weblite_codename1_mapper_DataMapper_set___java_util_Map_java_lang_Str
ing_java_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3326
#10 0x011d7f86 in 
nl_synobsys_bowlingscore_mirah_GameMapper_writeMap___java_util_Map_java_lang_Obj
ect at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/nl_synobsys_bowlingscore_mirah_GameMapper.m:307
#11 0x00071498 in 
virtual_ca_weblite_codename1_mapper_DataMapper_writeMap___java_util_Map_java_lan
g_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3470
#12 0x0007002d in 
ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java_lang_Ob
ject at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:2122
#13 0x00071257 in 
virtual_ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3318
#14 0x0006e1b6 in 
ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java_lang_Ob
ject at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:1959
#15 0x00071257 in 
virtual_ca_weblite_codename1_mapper_DataMapper_jsonify___java_lang_Object_R_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3318
#16 0x00071bc8 in 
ca_weblite_codename1_mapper_DataMapper_set___java_util_Map_java_lang_String_java
_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:2272
#17 0x0007af43 in 
virtual_ca_weblite_codename1_mapper_DataMapper_set___java_util_Map_java_lang_Str
ing_java_lang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3326
#18 0x011db53f in 
nl_synobsys_bowlingscore_mirah_StorageDataMapper_writeMap___java_util_Map_java_l
ang_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/nl_synobsys_bowlingscore_mirah_StorageDataMapper.m:214
#19 0x00071498 in 
virtual_ca_weblite_codename1_mapper_DataMapper_writeMap___java_util_Map_java_lan
g_Object at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3470
#20 0x00079991 in 
ca_weblite_codename1_mapper_DataMapper_writeMap___java_lang_Object_R_java_util_M
ap at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/ca_weblite_codename1_mapper_DataMapper.m:3074
#21 0x011dcb1a in 
virtual_nl_synobsys_bowlingscore_mirah_StorageDataMapper_writeMap___java_lang_Ob
ject_R_java_util_Map at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/nl_synobsys_bowlingscore_mirah_StorageDataMapper.m:567
#22 0x011f9aa6 in 
userclasses_StateMachine_onMain_ButtonTest2Action___com_codename1_ui_Component_c
om_codename1_ui_events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/userclasses_StateMachine.m:611
#23 0x00f51f58 in 
virtual_generated_StateMachineBase_onMain_ButtonTest2Action___com_codename1_ui_C
omponent_com_codename1_ui_events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/generated_StateMachineBase.m:1797
#24 0x00f51cae in 
generated_StateMachineBase_handleComponentAction___com_codename1_ui_Component_co
m_codename1_ui_events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/generated_StateMachineBase.m:1191
#25 0x00eb6098 in 
virtual_com_codename1_ui_util_UIBuilder_handleComponentAction___com_codename1_ui
_Component_com_codename1_ui_events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_util_UIBuilder.m:11052
#26 0x00eba53c in 
com_codename1_ui_util_UIBuilder_FormListener_actionPerformed___com_codename1_ui_
events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_util_UIBuilder_FormListener.m:413
#27 0x00735a44 in 
virtual_com_codename1_ui_events_ActionListener_actionPerformed___com_codename1_u
i_events_ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_events_ActionListener.m:68
#28 0x00dd2bcb in 
com_codename1_ui_util_EventDispatcher_fireActionEvent___com_codename1_ui_events_
ActionEvent at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_util_EventDispatcher.m:1265
#29 0x004bccd4 in com_codename1_ui_Button_fireActionEvent___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Button.m:1854
#30 0x004bdc48 in virtual_com_codename1_ui_Button_fireActionEvent___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Button.m:4607
#31 0x004bda71 in com_codename1_ui_Button_released___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Button.m:1934
#32 0x004bd738 in virtual_com_codename1_ui_Button_released___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Button.m:4631
#33 0x004c031b in com_codename1_ui_Button_pointerReleased___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Button.m:2181
#34 0x005a21b8 in virtual_com_codename1_ui_Component_pointerReleased___int_int 
at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Component.m:15510
#35 0x00796851 in com_codename1_ui_Form_pointerReleased___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Form.m:8558
#36 0x007980e8 in virtual_com_codename1_ui_Form_pointerReleased___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Form.m:12553
#37 0x0079273b in com_codename1_ui_Form_pointerReleased___int_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Form.m:8192
#38 0x005a21b8 in virtual_com_codename1_ui_Component_pointerReleased___int_int 
at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Component.m:15510
#39 0x005a20ab in 
com_codename1_ui_Component_pointerReleased___int_1ARRAY_int_1ARRAY at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Component.m:8590
#40 0x007b0058 in 
virtual_com_codename1_ui_Form_pointerReleased___int_1ARRAY_int_1ARRAY at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Form.m:12537
#41 0x006dc56a in com_codename1_ui_Display_handleEvent___int_R_int at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Display.m:6626
#42 0x006c67af in com_codename1_ui_Display_edtLoopImpl__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Display.m:2836
#43 0x006d2ae9 in com_codename1_ui_Display_mainEDTLoop__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_Display.m:2517
#44 0x00bc6dff in com_codename1_ui_RunnableWrapper_run__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_ui_RunnableWrapper.m:515
#45 0x00fdcbf6 in virtual_java_lang_Runnable_run__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/java_lang_Runnable.m:68
#46 0x0015d8dc in com_codename1_impl_CodenameOneThread_run__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/com_codename1_impl_CodenameOneThread.m:576
#47 0x00fdcbf6 in virtual_java_lang_Runnable_run__ at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/java_lang_Runnable.m:68
#48 0x0101c3ca in java_lang_Thread_runImpl___long at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/java_lang_Thread.m:272
#49 0x011c20cb in threadRunner at 
/var/folders/k7/b5qdhxt88v58wp008k8yxy180000gn/T/build4946292202552857607xxx/dis
t/TestMappers-src/nativeMethods.m:792
#50 0x06228ecf in _pthread_body ()

Original issue reported on code.google.com by st...@weblite.ca on 26 Jan 2015 at 5:38

GoogleCodeExporter commented 9 years ago
Here is the Java bytecode that produced it:

public void writeMap(Map dest, Object src) {
        // <editor-fold defaultstate="collapsed" desc="Compiled Code">
        /* 0: aload_0
         * 1: aload_1
         * 2: ldc           frameNumber
         * 4: aload_2
         * 5: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 8: invokevirtual nl/synobsys/bowlingscore/data/Frame.getFrameNumber:()I
         * 11: new           java/lang/Integer
         * 14: dup_x1
         * 15: swap
         * 16: invokespecial java/lang/Integer."<init>":(I)V
         * 19: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 22: aload_0
         * 23: aload_1
         * 24: ldc           throw1
         * 26: aload_2
         * 27: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 30: invokevirtual nl/synobsys/bowlingscore/data/Frame.getThrow1:()Ljava/lang/String;
         * 33: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 36: aload_0
         * 37: aload_1
         * 38: ldc           throw2
         * 40: aload_2
         * 41: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 44: invokevirtual nl/synobsys/bowlingscore/data/Frame.getThrow2:()Ljava/lang/String;
         * 47: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 50: aload_0
         * 51: aload_1
         * 52: ldc           throw3
         * 54: aload_2
         * 55: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 58: invokevirtual nl/synobsys/bowlingscore/data/Frame.getThrow3:()Ljava/lang/String;
         * 61: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 64: aload_0
         * 65: aload_1
         * 66: ldc           score
         * 68: aload_2
         * 69: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 72: invokevirtual nl/synobsys/bowlingscore/data/Frame.getScore:()I
         * 75: new           java/lang/Integer
         * 78: dup_x1
         * 79: swap
         * 80: invokespecial java/lang/Integer."<init>":(I)V
         * 83: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 86: aload_0
         * 87: aload_1
         * 88: ldc           class
         * 90: aload_2
         * 91: checkcast     nl/synobsys/bowlingscore/data/Frame
         * 94: invokevirtual java/lang/Object.getClass:()Ljava/lang/Class;
         * 97: invokevirtual ca/weblite/codename1/mapper/DataMapper.set:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/Object;)V
         * 100: return
         *  */
        // </editor-fold>
    }

I believe it is line 15

Original comment by st...@weblite.ca on 26 Jan 2015 at 5:40

GoogleCodeExporter commented 9 years ago
That does look a bit suspect.
#define swapStack(array, sp) { \
    struct elementStruct t = array[sp]; \
    array[sp] = array[sp - 1]; \
    array[sp - 1] = t; \
}

This is effectively copying a struct which might be a problem. If you change 
swapStack to this does it solve it:
#define swapStack(array, sp) { \
    javaTypes tt = array[sp].type; \
    elementUnion td = array[sp].data; \
    array[sp].type = array[sp - 1].type; \
    array[sp].data = array[sp - 1].data; \
    array[sp - 1].type = tt; \
    array[sp - 1].data = td; \
}

Original comment by shai.almog on 26 Jan 2015 at 5:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I get the same result after changing swapStack().  

I'm looking through the debugger at a few break points to see I can shed any 
light on this.

Original comment by st...@weblite.ca on 26 Jan 2015 at 6:19

GoogleCodeExporter commented 9 years ago
I seem to get good results by changing swapStack to:

#define swapStack(array, sp) { \
    struct elementStruct t = array[sp-1]; \
    array[sp-1] = array[sp - 2]; \
    array[sp - 2] = t; \
}

I'm still playing catchup here, but I believe the stack pointer is usually 
(always??) pointing to the *next* position where something can be added to the 
stack.  Therefore swapping the top 2 items in the stack actually entails 
swapping items at positions (sp-1 and sp-2), and not (sp and sp-1).

Do you see any flaws in my logic?  If not, can I commit this?

Original comment by st...@weblite.ca on 26 Jan 2015 at 6:57

GoogleCodeExporter commented 9 years ago
I have gone ahead and committed this.   I've gone through it with a number of 
test cases, and I'm fairly certain that this is correct.

(At the very least it corrects this issue).
https://code.google.com/p/codenameone/source/detail?r=2040

Original comment by st...@weblite.ca on 26 Jan 2015 at 7:15

GoogleCodeExporter commented 9 years ago
I was just commenting for you to go ahead and got a conflict ;-)

Original comment by shai.almog on 26 Jan 2015 at 7:16