BZ #97: i386 aborts when compiled with -O2

Status fields:

creation_ts:2008-08-16 20:35
component:vm
version:default branch
rep_platform:i386
op_sys:Linux
bug_status:RESOLVED
resolution:FIXED
reporter:twisti@complang.tuwien.ac.at
$ cacao
cacao: builtin.c:854: builtin_new: Assertion `c->state & 0x0002' failed.
Aborted (core dumped)

Core was generated by `cacao'.
Program terminated with signal 6, Aborted.
#0  0xb7c99947 in raise () from /lib/tls/libc.so.6
(gdb) bt
#0  0xb7c99947 in raise () from /lib/tls/libc.so.6
#1  0xb7c9b0c9 in abort () from /lib/tls/libc.so.6
#2  0xb7c9305f in __assert_fail () from /lib/tls/libc.so.6
#3  0xb7bc82ed in builtin_new (c=0x80a1500) at builtin.c:854
#4  0xb7bc830d in builtin_java_new (clazz=0x80a1500) at builtin.c:1000
#5  0xb7203556 in ?? ()
#6  0x080a1500 in ?? ()
#7  0xb7203518 in ?? ()
#8  0x00000000 in ?? ()

Comment #1 by twisti@complang.tuwien.ac.at on 2008-08-16 20:36:45

It seems the object layout is broken:

(gdb) p *c
$1 = {object = {header = {vftbl = 0x83da278, lockword = 0}, padding = {96, 138257568,
134864672, 0}}, flags = 0, name = 0x0, cpcount = 0, cptags = 0x0, cpinfos = 0x0,
  classrefcount = 2, classrefs = 0x83da3c8, extclassrefs = 0xa, parseddescsize = 16,
parseddescs = 0x8 <Address 0x8 out of bounds>, super = 0x83ed5a8, sub = 0x0,
  nextsub = 0x0, interfacescount = 0, interfaces = 0x0, fieldscount = 0, fields = 0x0,
methodscount = 138066552, methods = 0x83ed598, state = 137756016, index = 0,
  instancesize = 0, vftbl = 0x0, finalizer = 0x0, innerclasscount = 0, innerclass = 0x0,
declaringclass = {ref = 0x83bb0ec, cls = 0x83bb0ec, any = 0x83bb0ec},
  enclosingclass = {ref = 0x0, cls = 0x0, any = 0x0}, enclosingmethod = 0x0, packagename
= 0x0, sourcefile = 0x0, signature = 0x0, annotations = 0x20030,
  method_annotations = 0x82ffb10, method_parameterannotations = 0x25,
method_annotationdefaults = 0x83d1938, field_annotations = 0x83ed3b0, classloader = 0x5}

Maybe this is related to the java.lang.Class padding?  I have to add the size check.

Comment #2 by twisti@complang.tuwien.ac.at on 2008-08-16 21:30:51

No, the padding is OK:

(gdb) p *class_java_lang_Class
$3 = {object = {header = {vftbl = 0x83bb0ec, lockword = 0}, padding = {0, 0, 0, 0}},
flags = 524337, name = 0x805ec08, cpcount = 648, cptags = 0x8369818 "",
  cpinfos = 0x836bce8, classrefcount = 61, classrefs = 0x838af00, extclassrefs = 0x0,
parseddescsize = 8988, parseddescs = 0x838b1e0 "", super = 0x809df20, sub = 0x0,
  nextsub = 0x809fa50, interfacescount = 4, interfaces = 0x83870e0, fieldscount = 8,
fields = 0x8387110, methodscount = 75, methods = 0x83872c8, state = 10, index = 1,
  instancesize = 24, vftbl = 0x83bb0ec, finalizer = 0x0, innerclasscount = 3, innerclass
= 0x838dbb0, declaringclass = {ref = 0x0, cls = 0x0, any = 0x0},
  enclosingclass = {ref = 0x0, cls = 0x0, any = 0x0}, enclosingmethod = 0x0, packagename
= 0x8352168, sourcefile = 0x8370358, signature = 0x83703b8, annotations = 0x0,
  method_annotations = 0x0, method_parameterannotations = 0x0, method_annotationdefaults
= 0x0, field_annotations = 0x0, classloader = 0x0}

(gdb) call sizeof(dummy_java_lang_Class)
$5 = 24

Comment #3 by twisti@complang.tuwien.ac.at on 2008-08-17 12:53:13

This changeset breaks it:

http://mips.complang.tuwien.ac.at/hg/cacao/rev/ca65904a0c8b

Comment #4 by twisti@complang.tuwien.ac.at on 2008-08-17 13:58:58

It seems that the code patching code is reordered by the compiler:

0xb7bfae52 <patcher_aconst+50>: mov    (%esi),%edx      <-- get pr->mpc
0xb7bfae54 <patcher_aconst+52>: mov    0x14(%esi),%eax  <-- get pr->mcode
0xb7bfae57 <patcher_aconst+55>: mov    %ecx,0x1(%edi)   <-- patch of data
0xb7bfae5a <patcher_aconst+58>: mov    %ax,(%edx)       <-- patch instruction

I think we need to use icacheflush with some assembler like:

__asm__ __volatile__ ("" : : : "memory");

Comment #5 by twisti@complang.tuwien.ac.at on 2008-08-17 14:04:12

Yes, that fixes it:

0xb7be7002 <patcher_aconst+50>: mov    (%esi),%edx
0xb7be7004 <patcher_aconst+52>: mov    0x14(%esi),%eax
0xb7be7007 <patcher_aconst+55>: mov    %ax,(%edx)       <-- patch instruction
0xb7be700a <patcher_aconst+58>: mov    $0x1,%eax
0xb7be700f <patcher_aconst+63>: mov    %ecx,0x1(%edi)   <-- patch data

Comment #6 by twisti@complang.tuwien.ac.at on 2008-08-17 14:04:26

I'll commit a fix later.

Comment #7 by twisti@complang.tuwien.ac.at on 2008-08-18 11:24:05

Fix in: http://mips.complang.tuwien.ac.at/hg/cacao/rev/71ab2ca39dc5

A fix for x86_64 is still left.

Comment #8 by twisti@complang.tuwien.ac.at on 2008-08-18 11:35:12

Fix for x86_64: http://mips.complang.tuwien.ac.at/hg/cacao/rev/3f6b1c5148a9