Date: Tue, 8 Jun 1999 12:20:36 -0500 (EST) From: Gunther Schadow <gunther@aurora.rg.iupui.edu> To: freebsd-java@FreeBSD.ORG, kleine@ak.sax.de Subject: TYA bug or my fault? Message-ID: <199906081720.MAA20446@aurora.rg.iupui.edu>
next in thread | raw e-mail | index | archive | help
Moin! Albrecht, thanks for contributing TYA, it's great ... but here is a problem I encountered. I am not sure whether it's my fault or a TYA bug, anyway, java w/o TYA behaves differently from java with TYA. Here goes: The following snipped of my code (that compiles and runs to be tested) is an abstract class "test" that has a number of concrete subclasses (FA, FB, FC ...). class "test" maintains a Hashtable (all) of all its instantiations. Each of the concrete subclasses is instantiated only once, and that is done right in the class "test" as static member variables. The use of this weird construct is a dynamic library of special functions, that can be looked up by name. The lookup routine and the actual functions are not shown. import java.lang.*; import java.io.*; import java.util.Hashtable; public abstract class test { String name = null; private static final Hashtable all = new Hashtable(); protected test(String s) { name = s; System.out.println("defining test: `" + name + "'"); if(all.containsKey(s)) { System.out.println("all contains key " + s + " already? " + all); throw new IllegalArgumentException("test `" + s + "' is already defined"); } else { System.out.println("making new entry to all"); this.all.put(s, this); System.out.println("all now: " + all); } System.out.println("end of ctor"); } /** / public static final test f_A = new FA(); public static final test f_B = new FB(); public static final test f_C = new FC(); public static final test f_D = new FD(); public static final test f_E = new FE(); public static final test f_F = new FF(); / **/ public static final test f_A = FA.proto; public static final test f_B = FB.proto; public static final test f_C = FC.proto; public static final test f_D = FD.proto; public static final test f_E = FE.proto; public static final test f_F = FF.proto; /**/ public static void main(String args[]) { System.out.println(all); } } class FA extends test { FA() { super("A"); } public static final FA proto = new FA(); } class FB extends test { FB() { super("B"); } public static final FB proto = new FB(); } class FC extends test { FC() { super("C"); } public static final FC proto = new FC(); } class FD extends test { FD() { super("D"); } public static final FD proto = new FD(); } class FE extends test { FE() { super("E"); } public static final FE proto = new FE(); } class FF extends test { FF() { super("F"); } public static final FF proto = new FF(); } Witout TYA, what happens is that during initialization all concrete classes are instantiated and the hashtable populated. With TYA the hashtable remains empty! Without TYA: defining test: `A' making new entry to all all now: {A=FA@10c260b} end of ctor defining test: `B' making new entry to all all now: {B=FB@10c2627, A=FA@10c260b} end of ctor defining test: `C' making new entry to all all now: {C=FC@10c264a, B=FB@10c2627, A=FA@10c260b} end of ctor defining test: `D' making new entry to all all now: {D=FD@10c26bb, C=FC@10c264a, B=FB@10c2627, A=FA@10c260b} end of ctor defining test: `E' making new entry to all all now: {E=FE@10c26cd, D=FD@10c26bb, C=FC@10c264a, B=FB@10c2627, A=FA@10c260b} end of ctor defining test: `F' making new entry to all all now: {F=FF@10c272b, E=FE@10c26cd, D=FD@10c26bb, C=FC@10c264a, B=FB@10c2627, A=FA@10c260b} end of ctor {F=FF@10c272b, E=FE@10c26cd, D=FD@10c26bb, C=FC@10c264a, B=FB@10c2627, A=FA@10c260b} With TYA TYA 1.3v2 (for J117 / FreeBSD). Copyright (c) 1997,98,99 The TYA Team Contact The TYA Team via Albrecht Kleine <kleine@ak.sax.de> defining test: `A' defining test: `B' defining test: `C' defining test: `D' defining test: `E' defining test: `F' {} With shujit (that doesn't work for my real project for other reasons) shuJIT for Sun JVM/IA-32 Copyright 1998,1999 by SHUDO Kazuyuki defining test: `A' making new entry to all all now: {A=FA@10c25f8} end of ctor defining test: `B' making new entry to all all now: {B=FB@10c264f, A=FA@10c25f8} end of ctor defining test: `C' making new entry to all all now: {C=FC@10c2674, B=FB@10c264f, A=FA@10c25f8} end of ctor defining test: `D' making new entry to all all now: {D=FD@10c26e4, C=FC@10c2674, B=FB@10c264f, A=FA@10c25f8} end of ctor defining test: `E' making new entry to all all now: {E=FE@10c26f6, D=FD@10c26e4, C=FC@10c2674, B=FB@10c264f, A=FA@10c25f8} end of ctor defining test: `F' making new entry to all all now: {F=FF@10c2755, E=FE@10c26f6, D=FD@10c26e4, C=FC@10c2674, B=FB@10c264f, A=FA@10c25f8} end of ctor {F=FF@10c2755, E=FE@10c26f6, D=FD@10c26e4, C=FC@10c2674, B=FB@10c264f, A=FA@10c25f8} Obviously, TYA has problems with the self-instantiations of all the concrete classes, e.g.: class FA extends test { ... public static final FA proto = new FA(); } where test uses just the FA.proto instance to assign to its static member. This rather convoluted design can be straightened, by avoiding the self-instantiation of the "proto" and instantiate each concrete class only in the super class. So, it may be that I am using Java in a wrong way, and it may be that the fact JDK's java and shujit lets me do that is their fault. But it may also be that my convoluted design has exposed a tricky TYA bug, just like Donald Knuth's trip/trap tests were designed to do the most awkward things conceivable to find hidden bugs. This examination of the problem has given me a work around, I hope that it can help to make TYA even better! Thanks, -Gunther Gunther Schadow ----------------------------------- http://aurora.rg.iupui.edu Regenstrief Institute for Health Care 1001 W 10th Street RG5, Indianapolis IN 46202, Phone: (317) 630 7960 schadow@aurora.rg.iupui.edu ---------------------- #include <usual/disclaimer> To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199906081720.MAA20446>