39ff0e721f00f8a7138135cdce832e61e969d294
[org.ibex.core.git] / README
1 ==============================================================================
2 XWT README
3
4               
5 ______________________________________________________________________________
6 Documentation
7         \r
8 If you're new to XWT, you should read the documentation in the order
9 presented below:
10
11 - README [this file]
12         
13       Start here. Includes a map of all other documentation and a
14       description of the directory strucure
15
16 - The XWT home page [http://www.xwt.org/]
17           
18 - The XWT tutorial [http://www.xwt.org/tutorial.html]
19
20       Gentle introduction to what XWT is, and how to write
21       .xwt's. Good for anybody who wants to write XWT applications.
22
23 - The XWT reference [http://www.xwt.org/reference.html]
24         
25       Precise, technical spec of exactly how XWT works. Assumes
26       familiarity with XWT (ie, you've read the tutorial). This is the
27       authoritative source for how an XWT engine should
28       behave.
29
30 ______________________________________________________________________________
31 Directory Structure
32
33 /
34    AUTHORS                - people involved in developing XWT
35    README                 - this file
36    COPYING                - copyright information for all files in this distro
37    TM                     - trademark information for XWT
38    Makefile               - build file for gcc 3.3
39    next.build             - the build id of the next build to be generated
40    bin/                   - all binary stuff generated by xwt builds
41    gcc/                   - build area for a custom copy of gcc3.3 and binutils2.13
42        Makefile           - will download, configure, compile, and private-install gcc3.3/binutils2.13
43    lib/                   - any third-party binary stuff needed during the build process
44        javago             - a copy of the javago post-compilation bytecode inliner
45        netscape.jar       - minimal set of classes required for compiling against Netcape's Applet interfaces
46        msjvm.jar          - minimal set of classes required for compiling against Microsoft's Applet interfaces
47        jump.jar           - the jump2 bytecode-to-palmos translator
48        libgcj-minimal.jar - a tiny portion of libgcj.jar; allows java->bytecode compilation without gcj
49    src/                   - all java source files and xwt sources go here
50        org/
51            bouncycastle/  - the BouncyCastle Crypto Library
52            mozilla/       - a copy of Rhino, the Mozilla JavaScript interpreter
53            xwt/builtin/   - .xwt's and .png's that are essential to bootstrapping the engine
54            xwt/plat/      - platform-specific code
55
56 ______________________________________________________________________________
57 Build Targets and Requirements
58
59 Build requirements:
60 - jdk 1.4+
61 - jikes (warning: Jikes 1.16 has a fatal bug; use 1.15)
62 - gcj 3.3+
63 - binutils 2.13+
64 - fastjar
65
66 If you already have a suitably configured gcj 3.3 and binutils 2.13+
67 you can set "gcc_path" to point at its installation location;
68 otherwise the Makefile will download, configure, compile, and install
69 gcc and binutils.
70
71 Public build targets:
72
73     compile       - compiles all .java files into bin/*.class
74     Win32         - Win95 or later (bin-Win32/xwt.exe)
75     Linux         - Linux 2.2 or later (bin-Linux/xwt.linux)
76     Java2         - Any Java 1.2+ compliant JVM
77     clean         - cleanup
78
79
80 ______________________________________________________________________________
81 inet_addr patch
82
83 Index: java/net/natInetAddress.cc
84 ===================================================================
85 RCS file: /cvs/gcc/gcc/libjava/java/net/natInetAddress.cc,v
86 retrieving revision 1.18.18.1
87 diff -u -r1.18.18.1 natInetAddress.cc
88 --- java/net/natInetAddress.cc  4 Mar 2002 20:02:19 -0000       1.18.18.1
89 +++ java/net/natInetAddress.cc  27 May 2002 22:54:40 -0000
90 @@ -9,6 +9,7 @@
91  details.  */
92
93  #include <config.h>
94 +#include <platform.h>
95
96  #ifdef WIN32
97
98 Index: include/win32.h
99 ===================================================================
100 RCS file: /cvs/gcc/gcc/libjava/include/win32.h,v
101 retrieving revision 1.3.8.5
102 diff -u -r1.3.8.5 win32.h
103 --- include/win32.h     24 Apr 2002 01:04:45 -0000      1.3.8.5
104 +++ include/win32.h     27 May 2002 22:54:40 -0000
105 @@ -35,4 +35,8 @@
106     ARRAY and return the exact number of values stored.  */
107  extern int backtrace (void **__array, int __size);
108
109 +// configure cannot correctly detect inet_addr due to Win32's
110 +// oddball header naming scheme
111 +#define HAVE_INET_ADDR
112 +
113  #endif /* __JV_WIN32_H__ */
114
115
116
117 ______________________________________________________________________________
118 Throwable.printStackTrace() patch
119
120 Index: Class.h
121 ===================================================================
122 RCS file: /cvs/gcc/gcc/libjava/java/lang/Class.h,v
123 retrieving revision 1.43
124 diff -u -r1.43 Class.h
125 --- Class.h     21 Dec 2001 19:47:50 -0000      1.43
126 +++ Class.h     24 Apr 2002 03:06:14 -0000
127 @@ -308,6 +308,7 @@
128    friend void _Jv_LayoutVTableMethods (jclass klass);
129    friend void _Jv_SetVTableEntries (jclass, _Jv_VTable *);
130    friend void _Jv_MakeVTable (jclass);
131 +  friend JArray<java::lang::reflect::Method*>* _Jv_GetAllMethods();
132  
133    // Return array class corresponding to element type KLASS, creating it if
134    // necessary.
135 Index: ClassLoader.java
136 ===================================================================
137 RCS file: /cvs/gcc/gcc/libjava/java/lang/ClassLoader.java,v
138 retrieving revision 1.16
139 diff -u -r1.16 ClassLoader.java
140 --- ClassLoader.java    7 Dec 2001 23:34:12 -0000       1.16
141 +++ ClassLoader.java    24 Apr 2002 03:06:14 -0000
142 @@ -577,4 +577,8 @@
143      // Default to returning null.  Derived classes implement this.
144      return null;
145    }
146 +
147 +  static native java.lang.reflect.Method[] getAllMethods();
148 +  static native long[] getAllMethodAddrs();
149 +
150  }
151 Index: Throwable.java
152 ===================================================================
153 RCS file: /cvs/gcc/gcc/libjava/java/lang/Throwable.java,v
154 retrieving revision 1.10
155 diff -u -r1.10 Throwable.java
156 --- Throwable.java      24 Feb 2001 03:52:49 -0000      1.10
157 +++ Throwable.java      24 Apr 2002 03:06:14 -0000
158 @@ -123,21 +123,64 @@
159      printStackTrace (writer);
160    }
161  
162 +  private native static long longFromStackTraceBytes(byte[] stackTrace, int i);
163 +
164    public void printStackTrace (PrintWriter wr)
165    {
166 -    try
167 -      {
168 -       CPlusPlusDemangler cPlusPlusFilter = new CPlusPlusDemangler (wr);
169 -       PrintWriter writer = new PrintWriter (cPlusPlusFilter);
170 -       printRawStackTrace (writer);    
171 -       writer.close ();
172 -       if (cPlusPlusFilter.written == 0) // The demangler has failed...
173 -         printRawStackTrace (wr);
174 +      try
175 +          {
176 +              CPlusPlusDemangler cPlusPlusFilter = new CPlusPlusDemangler (wr);
177 +              PrintWriter writer = new PrintWriter (cPlusPlusFilter);
178 +              printRawStackTrace (writer);     
179 +              writer.close ();
180 +              if (cPlusPlusFilter.written > 0) return;
181 +          }
182 +      catch (Exception e1)
183 +          {
184 +          }
185 +
186 +      wr.println(toString());
187 +      if (stackTrace == null) {
188 +          wr.flush();
189 +          return;
190        }
191 -    catch (Exception e1)
192 -      {
193 -       printRawStackTrace (wr);
194 +      
195 +      long[] allAddrs = ClassLoader.getAllMethodAddrs();
196 +      java.lang.reflect.Method[] meths = ClassLoader.getAllMethods();
197 +      
198 +      // FIXME: assumes little endian
199 +      for(int i=0; i<stackTrace.length; i++) {
200 +          long addr = longFromStackTraceBytes(stackTrace, i);
201 +          if (addr == 0) break;
202 +          
203 +          int whichMethod = -1;
204 +          for(int j=0; j<allAddrs.length; j++) {
205 +              if (allAddrs[j] <= addr &&
206 +                  (whichMethod == -1 || allAddrs[whichMethod] < allAddrs[j])) {
207 +                  whichMethod = j;
208 +              }
209 +          }
210 +          
211 +          if (whichMethod == -1) {
212 +              wr.println("[" + Long.toString(addr, 16) + "]  " + "??");
213 +              continue;
214 +          }
215 +          
216 +          if (meths[whichMethod].getDeclaringClass().getName().equals("gnu.gcj.runtime.FirstThread") &&
217 +              meths[whichMethod].getName().equals("call_main"))
218 +              break;
219 +          
220 +          wr.println("    [" + Long.toString(addr, 16) + "] " +
221 +                     meths[whichMethod].getDeclaringClass().getName() + "." +
222 +                     meths[whichMethod].getName() + "() " +
223 +                     "+" + (addr - allAddrs[whichMethod])
224 +                     );
225 +          
226 +          if (java.lang.Thread.class.isAssignableFrom(meths[whichMethod].getDeclaringClass()) &&
227 +              meths[whichMethod].getName().equals("run"))
228 +              break;
229        }
230 +      wr.flush();
231    }
232  
233    public Throwable ()
234 Index: natClassLoader.cc
235 ===================================================================
236 RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
237 retrieving revision 1.47.8.1
238 diff -u -r1.47.8.1 natClassLoader.cc
239 --- natClassLoader.cc   2 Apr 2002 22:19:55 -0000       1.47.8.1
240 +++ natClassLoader.cc   24 Apr 2002 03:06:14 -0000
241 @@ -40,6 +40,10 @@
242  #include <java/lang/StringBuffer.h>
243  #include <java/io/Serializable.h>
244  #include <java/lang/Cloneable.h>
245 +#include <java/lang/reflect/Method.h>
246 +
247 +#include<java/lang/reflect/Constructor.h>
248 +#include<gcj/method.h>
249  
250  // FIXME: remove these.
251  #define CloneableClass java::lang::Cloneable::class$
252 @@ -347,6 +351,50 @@
253  static jclass loaded_classes[HASH_LEN];
254  
255  // This is the root of a linked list of classes
256 +
257 +JArray<java::lang::reflect::Method*>*
258 +java::lang::ClassLoader::getAllMethods()
259 +{
260 +    return _Jv_GetAllMethods();
261 +}
262 +
263 +JArray<jlong>*
264 +java::lang::ClassLoader::getAllMethodAddrs()
265 +{
266 +    JArray<java::lang::reflect::Method*>* arr = _Jv_GetAllMethods();
267 +    java::lang::reflect::Method** el = (java::lang::reflect::Method**)elements(arr);
268 +    JArray<jlong>* ret = JvNewLongArray(arr->length);
269 +    jlong* retel = (jlong*)elements(ret);
270 +    for(int i=0; i<arr->length; i++)
271 +        retel[i] = (jlong)((unsigned int)(_Jv_FromReflectedMethod (el[i])->ncode));
272 +    return ret;
273 +}
274 +
275 +JArray<java::lang::reflect::Method*>*
276 +_Jv_GetAllMethods()
277 +{
278 +  int numMethods = 0;
279 +
280 +  for(int i=0; i<HASH_LEN; i++)
281 +      for(jclass c = loaded_classes[i]; c; c = c->next)
282 +          numMethods += c->getDeclaredMethods()->length;
283 +
284 +  JArray<java::lang::reflect::Method*>* ret =
285 +    (JArray<java::lang::reflect::Method*>*)
286 +    JvNewObjectArray(numMethods, &java::lang::reflect::Method::class$, NULL);
287 +
288 +  java::lang::reflect::Method** el = (java::lang::reflect::Method**)elements(ret);
289 +
290 +  for(int i=0; i<HASH_LEN; i++)
291 +      for(jclass c = loaded_classes[i]; c; c = c->next) {
292 +          JArray<java::lang::reflect::Method*>* methods = c->getDeclaredMethods();
293 +          jint len = methods->length;
294 +          java::lang::reflect::Method** meths = (java::lang::reflect::Method**)elements(methods);
295 +          for(int j=0; j<len; j++) el[--numMethods] = meths[j];
296 +      }
297 +
298 +  return ret;
299 +}
300  
301  \f
302  
303 Index: natThrowable.cc
304 ===================================================================
305 RCS file: /cvs/gcc/gcc/libjava/java/lang/natThrowable.cc,v
306 retrieving revision 1.11
307 diff -u -r1.11 natThrowable.cc
308 --- natThrowable.cc     7 Feb 2002 19:26:06 -0000       1.11
309 +++ natThrowable.cc     24 Apr 2002 03:06:14 -0000
310 @@ -32,6 +32,7 @@
311  #include <stdio.h>
312  
313  #include <unistd.h>
314 +#include <platform.h>
315  
316  #ifdef HAVE_EXECINFO_H
317  #include <execinfo.h>
318 @@ -102,3 +103,18 @@
319  #endif /* HAVE_BACKTRACE */
320    wr->flush ();
321  }
322 +
323 +// Returns the i^th call address in the stackTrace member, or 0 if i
324 +// is beyond the end of the trace. This has to be done in C++ because
325 +// the addresses in stackTrace are the same width as the platform's
326 +// pointers (which is unknown to Java code), and stackTrace is a
327 +// byte[] using the platform's endianness (which is unknown to Java
328 +// code).
329 +jlong
330 +java::lang::Throwable::longFromStackTraceBytes(jbyteArray stackArr, jint i)
331 +{
332 +    if (i * sizeof(void*) > stackArr->length) return 0;
333 +    unsigned int* stack = (unsigned int*)elements(stackArr);
334 +    return (jlong)stack[i];
335 +}
336 +
337
338
339
340
341