History

Fixed two bugs with method inheritance and superclass field usage

Dmitry Kabak (userdima committed 13 years ago

Commit 92189291 parent 26779081 file · +35 −20Browse files

Showing the changes to java/appl/java/classloader.b (1 of 1 file). Show all

Unified · Split

java/appl/java/classloader.b+35−20
@@ -1668,6 +1668,7 @@ multianewarray(ndim: int, c: ref Class, etype: int, bounds: array of int): ref A · 1667 unmodified lines
16681668
16691669 arraycopy(src: ref Array, sx: int, dst: ref Array, dx: int, n: int)
16701670 {
1671+ trace(JDEBUG, sys->sprint("Arraycopy called: src[%d], dst[%d], %d, %d, %d", len src.holder, len dst.holder, sx, dx, n));
16711672 if (arrayclass == nil)
16721673 loadarrayclass();
16731674 if (src == nil || dst == nil)
@@ -1692,6 +1693,7 @@ arraycopy(src: ref Array, sx: int, dst: ref Array, dx: int, n: int) · 18 unmodified lines
16921693 if (sx < 0 || dx < 0 || n < 0 || sx + n > len src.holder || dx + n > len dst.holder || sx > 2147483647 - n || dx > 2147483647 - n)
16931694 sthrow("ArrayIndexOutOfBoundsException");
16941695 dst.holder[dx:] = sa[sx:sx + n];
1696+ trace(JDEBUG, "Arraycopy completed successfully");
16951697 }
16961698
16971699 #
@@ -1777,25 +1779,23 @@ drem(x, y: real): real · 79 unmodified lines
17771779
17781780 Class.run(c: self ref Class, args: list of string)
17791781 {
1780− m := c.findsmethod(MAINFIELD, VOIDSIGNATURE);
1782+ m := c.findsmethod(MAINFIELD, MAINSIGNATURE);
17811783 if (m == nil)
17821784 loaderror( nosuchmethod, sys->sprint("%s: missing static method main", c.name));
17831785 main = c;
1784− #if (arrayclass == nil)
1785− # loadarrayclass();
1786− #if (stringclass == nil)
1787− # loadstringclass();
1788− #n := len args;
1789− #h := array[n] of ref JavaString;
1790− #d := stringclass.moddata;
1791− #for (i := 0; i < n; i++) {
1792− # h[i] = ref JavaString(d, hd args);
1793− # args = tl args;
1794− #}
1795− #c.xeq(m.value, ref Array(arraymd, h, 1, stringclass, 0));
1786+ if (arrayclass == nil)
1787+ loadarrayclass();
1788+ if (stringclass == nil)
1789+ loadstringclass();
1790+ n := len args;
1791+ h := array[n] of ref JavaString;
1792+ d := stringclass.moddata;
1793+ for (i := 0; i < n; i++) {
1794+ h[i] = ref JavaString(d, hd args);
1795+ args = tl args;
1796+ }
17961797 getthreaddata();
1797− #r := jassist->mcalla(c.mod, m.value, ref Array(arraymd, h, 1, stringclass, 0));
1798− r := jassist->mcall0(c.mod, m.value);
1798+ r := jassist->mcalla(c.mod, m.value, ref Array(arraymd, h, 1, stringclass, 0));
17991799 delthreaddata();
18001800 }
18011801
@@ -1935,6 +1935,15 @@ Class.resolve(c: self ref Class) · 133 unmodified lines
19351935 sz += sizeof(t.signature);
19361936 sd = f :: sd;
19371937 } else {
1938+ superfield: ref Field;
1939+ if (c.super != nil)
1940+ superfield = c.super.findofield(t.field);
1941+ if (superfield != nil) {
1942+ trace(JDEBUG, sys->sprint("%s: superclass data", t.field));
1943+ p[i].what = PVALUE;
1944+ p[i].value = superfield.value;
1945+ continue;
1946+ }
19381947 trace(JDEBUG, sys->sprint("%s: new data", t.field));
19391948 oz = alignto(oz, t.signature);
19401949 p[i].what = PVALUE;
@@ -2059,24 +2068,28 @@ Class.makeobjtype(c: self ref Class) · 118 unmodified lines
20592068 #
20602069 Class.makevmtable(c: self ref Class, m: list of ref Field, z: int): array of Method
20612070 {
2071+ trace(JDEBUG, sys->sprint("Makevmtable for %s, %d", c.name, z));
20622072 t := array[z] of Method;
20632073 if (c.super != nil) {
20642074 s := c.super.virtualmethods;
20652075 n := len s;
2066− for (i := 0; i < n; i++)
2076+ for (i := 0; i < n; i++) {
2077+ trace(JDEBUG, sys->sprint("Makevmtable adding super method %s", s[i].field.field + s[i].field.signature));
20672078 t[i] = s[i];
2079+ }
20682080 }
20692081 while (m != nil) {
20702082 f := hd m;
20712083 n := f.value;
2072− # TODO: check if we don't have this method in links, so just use parent class's one
2073− trace(JDEBUG, sys->sprint("Makevmtable for %s, %d", c.name, z));
2084+ trace(JDEBUG, sys->sprint("Makevmtable checking %s %d %d", f.field + f.signature, n, f.flags));
20742085 {
20752086 f.value = c.getmethod(f.field, f.signature, f.flags);
20762087 }
20772088 exception e {
20782089 JCLDREX + nosuchmethod + "*" =>
2079− ; # silently ignore
2090+ # TODO: check if we really have it in superclass vmtable
2091+ m = tl m;
2092+ continue;
20802093 }
20812094 t[n].field = f;
20822095 t[n].class = c;
@@ -2589,6 +2602,8 @@ Class.getmethod(c: self ref Class, f, s: string, flags: int): int · 506 unmodified lines
25892602 if (l[i].name == m)
25902603 return i;
25912604 }
2605+ if (flags & ACC_NATIVE)
2606+ trace(JDEBUG, sys->sprint("Native method %s not found in %s", m, c.name));
25922607 if (!(flags & (ACC_ABSTRACT | ACC_NATIVE)))
25932608 {
25942609 loaderror( nosuchmethod, sys->sprint("method %x %s '%s' %s not found", flags, f, s, m) );
@@ -2753,7 +2768,7 @@ Class.resolvereloc(c: self ref Class, r, s: string, flags: int): (int, int) · 158 unmodified lines
27532768 f: ref Field;
27542769 case flags & Rmask {
27552770 Rgetputfield =>
2756− f = findfield(c.objectdata, r);
2771+ f = c.findofield(r);
27572772 if (f == nil)
27582773 loaderror(nosuchfield, sys->sprint("%s not resolved in class %s", r, c.name));
27592774 else {