~angelsl/ubuntu/wily/gcc-5/mips-cross

« back to all changes in this revision

Viewing changes to debian/FAQ.gcj

  • Committer: angelsl
  • Date: 2015-10-30 03:30:35 UTC
  • Revision ID: angelsl-20151030033035-rmug41zm8hyjgisg
Original import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
The GCJ FAQ
 
2
===========
 
3
 
 
4
      The latest version of this document is always available at
 
5
      http://gcc.gnu.org/java/faq.html.
 
6
 
 
7
        General Questions
 
8
 
 
9
            What license is used for libgcj?
 
10
            How can I report a bug in libgcj?
 
11
            How can I contribute to libgcj
 
12
            Is libgcj part of GCC?
 
13
            Will gcj and libgcj work on my machine?
 
14
            How can I debug my Java program?
 
15
            Can I interface byte-compiled and native java code?
 
16
 
 
17
 
 
18
        Java Feature Support
 
19
 
 
20
            What Java API's are supported? How complete is
 
21
              the support?
 
22
            Does GCJ support using straight C native methods
 
23
              ala JNI?
 
24
            Why does GCJ use CNI?
 
25
            What is the state of AWT support?
 
26
            How about support for Swing ?
 
27
            What support is there for RMI ?
 
28
            Can I use any code from other OpenSource projects
 
29
              to supplement libgcj's current features ?
 
30
            What features of the Java language are/arn't supported
 
31
 
 
32
 
 
33
        Build Issues
 
34
 
 
35
            I need something more recent than the last release; how
 
36
                  should I build it?
 
37
            Linker bug on Solaris
 
38
            Can I configure/build in the source tree?
 
39
            My libgcj build fails with "invalid use of undefined type
 
40
                  struct sigcontext_struct"
 
41
 
 
42
 
 
43
        Gcj Compile/Link Questions
 
44
 
 
45
            Why do I get undefined reference to `main' errors?
 
46
            Can GCJ only handle source code?
 
47
            "gcj -C" Doesn't seem to work like javac/jikes. Whats going on?
 
48
            Where does GCJ look for files?
 
49
            How does gcj resolve wether to compile .class or .java files?
 
50
            I'm getting link errors!
 
51
            I'm getting 'undefined symbol: __dso_handle'
 
52
 
 
53
 
 
54
        Runtime Questions
 
55
 
 
56
            My program is dumping core! What's going on?
 
57
            When I run the debugger I get a SEGV in the GC! What's going on?
 
58
            I have just compiled and benchmarked my Java application
 
59
            and it seems to be running slower than than XXX JIT JVM. Is there
 
60
            anything I can do to make it go faster?
 
61
            Can I profile Garbage Collection?
 
62
            How do I increase the runtime's initial and maximum heap sizes?
 
63
            How can I profile my application?
 
64
            My program seems to hang and doesn't produce any output
 
65
 
 
66
 
 
67
        Programming Issues
 
68
 
 
69
            Are there any examples of how to use CNI?
 
70
            Is it possible to invoke GCJ compiled Java code from a
 
71
            C++ application?
 
72
 
 
73
General Questions
 
74
=================
 
75
 
 
76
      1.1 What license is used for libgcj?
 
77
 
 
78
          libgcj is distributed under the GPL, with the 'libgcc exception'.
 
79
          This means that linking with libgcj does not by itself cause
 
80
          your program to fall under the GPL.  See LIBGCJ_LICENSE in
 
81
          the source tree for more details.
 
82
 
 
83
      1.2 How can I report a bug in libgcj?
 
84
 
 
85
          libgcj has a corresponding Gnats bug database which you can
 
86
          browse. You can also submit new bug reports from the Gnats
 
87
          page.
 
88
 
 
89
      1.3 How can I contribute to libgcj?
 
90
 
 
91
          You can send simple bug fixes in as patches. Please follow
 
92
          the GCC guidelines for submitting patches. For more complex
 
93
          changes, you must sign copyright over to the Free Software
 
94
          Foundation. See the contribution page for details.
 
95
 
 
96
      1.4 Is libgcj part of GCC?
 
97
 
 
98
          Yes, libgcj is now part of GCC. It can be downloaded,
 
99
          configured and built as one single tree.
 
100
 
 
101
      1.5 Will gcj and libgcj work on my machine?
 
102
 
 
103
          Gcj and libgcj are known to work more or less with IA-32 and
 
104
          Sparc Solaris, Tru64 Unix, as well as IA-32, IA-64, Alpha,
 
105
          and PowerPC Linux. They might work on other
 
106
          systems. Generally speaking, porting to a new system should
 
107
          not be hard. This would be a good way to volunteer.
 
108
 
 
109
      1.6 How can I debug my Java program?
 
110
 
 
111
          gdb 5.0 includes support for debugging gcj-compiled Java
 
112
          programs. For more information please read Java Debugging
 
113
          with gdb.
 
114
 
 
115
      1.7 Can I interface byte-compiled and native java code
 
116
 
 
117
          libgcj has a bytecode interpreter that allows you to mix
 
118
          .class files with compiled code. It works pretty
 
119
          transparently: if a compiled version of a class is not found
 
120
          in the application binary or linked shared libraries, the
 
121
          class loader will search for a bytecode version in your
 
122
          classpath, much like a VM would. Be sure to build libgcj
 
123
          with the --enable-interpreter option to enable this
 
124
          functionality.
 
125
 
 
126
          The program "gij" provides a front end to the interpreter
 
127
          that behaves much like a traditional virtual machine. You
 
128
          can even use "gij" to run a shared library which is compiled
 
129
          from java code and contains a main method:
 
130
 
 
131
          $ gcj -shared -o lib-HelloWorld.so HelloWorld.java
 
132
          $ gij HelloWorld
 
133
 
 
134
          This works because gij uses Class.forName, which knows how
 
135
          to load shared objects.
 
136
 
 
137
Java Feature Support
 
138
====================
 
139
 
 
140
      2.1 What Java API's are supported? How complete is
 
141
        the support?
 
142
 
 
143
          Matt Welsh writes:
 
144
 
 
145
            Just look in the 'libjava' directory of libgcj and see
 
146
            what classes are there. Most GUI stuff isn't there yet,
 
147
            that's true, but many of the other classes are easy to add
 
148
            if they don't yet exist.
 
149
 
 
150
            I think it's important to stress that there is a big
 
151
            difference between Java and the many libraries which Java
 
152
            supports. Unfortunately, Sun's promise of "write once, run
 
153
            everywhere" assumes much more than a JVM: you also need
 
154
            the full set of JDK libraries. Considering that new Java
 
155
            APIs come out every week, it's going to be impossible to
 
156
            track everything.
 
157
 
 
158
            To make things worse, you can't simply run Sun's JDK
 
159
            classes on any old JVM -- they assume that a bunch of
 
160
            native methods are also defined. Since this native method
 
161
            requirement isn't defined by the JDK specs, you're
 
162
            effectively constrained to using Sun's JVMs if you want to
 
163
            use Sun's JDK libraries. Oh yes -- you could also
 
164
            reimplement all of those native methods yourself, and make
 
165
            sure they behave exactly as Sun's do. Note that they're
 
166
            undocumented!
 
167
 
 
168
      2.2 Does GCJ support using straight C native methods
 
169
         ala JNI?
 
170
 
 
171
          Yes. libgcj now has experimental support for JNI, in
 
172
          addition to its native Compiled Native Interface (CNI). gcjh
 
173
          will generate JNI stubs and headers using the "-jni"
 
174
          option. However, we do prefer CNI: it is more efficient,
 
175
          easier to write, and (at least potentially) easier to debug.
 
176
 
 
177
      2.3 Why does GCJ use CNI?
 
178
 
 
179
          Per Bothner explains:
 
180
 
 
181
            We use CNI because we think it is a better solution,
 
182
            especially for a Java implementation that is based on the
 
183
            idea that Java is just another programming language that
 
184
            can be implemented using standard compilation
 
185
            techniques. Given that, and the idea that languages
 
186
            implemented using Gcc should be compatible where it makes
 
187
            sense, it follows that the Java calling convention should
 
188
            be as similar as practical to that used for other
 
189
            languages, especially C++, since we can think of Java as a
 
190
            subset of C++. CNI is just a set of helper functions and
 
191
            conventions built on the idea that C++ and Java have the
 
192
            *same* calling convention and object layout; they are
 
193
            binary compatible. (This is a simplification, but close
 
194
            enough.)
 
195
 
 
196
      2.4 What is the state of AWT support?
 
197
 
 
198
          Work is in progress to implement AWT and Java2D. We intend
 
199
          to support both GTK and xlib peers written using CNI. Some
 
200
          components are already working atop the xlib peers.
 
201
 
 
202
      2.5 How about support for Swing?
 
203
 
 
204
          Once AWT support is working then Swing support can be
 
205
          considered. There is at least one free-software partial
 
206
          implementations of Swing that may be usable.
 
207
 
 
208
      2.6 What support is there for RMI?
 
209
 
 
210
         RMI code exists on the CVS trunk (aka gcc 3.1), but it has
 
211
         not been heavily tested.  This code was donated by
 
212
         Transvirtual Technologies.
 
213
 
 
214
      2.7 Can I use any code from other OpenSource
 
215
          projects to supplement libgcj's current features?
 
216
 
 
217
           Certainly. However, in many cases, if you wanted to
 
218
           contribute the code back into the official libgcj
 
219
           distribution, we would require that the original author(s)
 
220
           assign copyright to the Free Software Foundation.  As of
 
221
           March 6, 2000, libgcj has been relicenced, and copyright
 
222
           has been assigned to the FSF. This allows us to share and
 
223
           merge much of the libgcj codebase with the Classpath
 
224
           project.  Our eventual goal is for Classpath to be an
 
225
           upstream source provider for libgcj, however it will be
 
226
           some time before this becomes reality: libgcj and Classpath
 
227
           have different implementations of many core java
 
228
           classes. In order to merge them, we need to select the best
 
229
           (most efficient, cleanest) implementation of each
 
230
           method/class/package, resolve any conflicts created by the
 
231
           merge, and test the final result.  Needless to say, this is
 
232
           a lot of work. If you can help out, please let us know!
 
233
 
 
234
      2.8 What features of the Java language are/aren't supported.
 
235
 
 
236
          GCJ supports all Java language constructs as per the Java
 
237
          language Specification.  Recent GCJ snapshots have added
 
238
          support for most JDK1.1 (and beyond) language features,
 
239
          including inner classes.
 
240
 
 
241
Build Issues
 
242
============
 
243
 
 
244
      3.1 I need something more recent than the last release.
 
245
          How should I build it?
 
246
 
 
247
          Please read here: http://gcc.gnu.org/java/build-snapshot.html
 
248
 
 
249
      3.2 Linker bug on Solaris
 
250
 
 
251
          There is a known problem with the native Solaris linker when
 
252
          using gcc/gcj. A good indication you've run into this
 
253
          problem is if you get an error that looks like the following
 
254
          when building libgcj:
 
255
 
 
256
ld: warning: option -o appears more than once, first setting taken
 
257
ld: fatal: file libfoo.so: cannot open file: No such file or directory
 
258
ld: fatal: File processing errors. No output written to .libs/libfoo.so
 
259
collect2: ld returned 1 exit status
 
260
 
 
261
          A known workaround for this and other reported link problems
 
262
          on the various releases of Solaris is to build gcc/gcj with
 
263
          the latest GNU binutils instead of the native Solaris
 
264
          ld. The most straightforward way to do this is to build and
 
265
          install binutils, and then reference it in the configure for
 
266
          gcc via --with-ld=/path_to_binutils_install/bin/ld
 
267
          (--with-as may also be similarly specified but is not
 
268
          believed to be required).
 
269
 
 
270
          Please note, gcc/gcj must be built using GNU ld prior to
 
271
          doing a clean build of libgcj!
 
272
 
 
273
      3.3 Can I configure/build in the source tree?
 
274
 
 
275
          No.  You cannot configure/build in the source tree.  If you
 
276
          try, you'll see something like:
 
277
 
 
278
              $ ./configure [...]
 
279
              Configuring for a i686-pc-linux-gnu host.
 
280
              *** Cannot currently configure in source tree.
 
281
 
 
282
          Instead, you must build in another directory.  E.g.:
 
283
 
 
284
              $ mkdir build
 
285
              $ cd build
 
286
              $ ../configure [...]
 
287
 
 
288
      3.4 My libgcj build fails with "invalid use of undefined type
 
289
          struct sigcontext_struct"
 
290
 
 
291
          If you're using Linux, this probably means you need to
 
292
          upgrade to a newwer, glibc (libc6) based Linux
 
293
          distribution. libgcj does not support the older linux libc5.
 
294
          It might be possible to get a working libgcj by changing
 
295
          occurances of "sigcontext_struct" to "sigcontext", however
 
296
          this has not been tested.  Even if it works, it is likely
 
297
          that there are other issues with older libc versions that
 
298
          would prevent libgcj from working correctly (threads bugs,
 
299
          for example).
 
300
 
 
301
Gcj Compile/Link Questions
 
302
==========================
 
303
 
 
304
      4.1 Why do I get undefined reference to `main' errors?
 
305
 
 
306
          When using gcj to link a Java program, you must use the --main=
 
307
          option to indicate the class that has the desired main method.
 
308
          This is because every Java class can have a main method, thus
 
309
          you have to tell gcj which one to use.
 
310
 
 
311
      4.2 Can GCJ only handle source code?
 
312
 
 
313
          GCJ will compile both source (.java) and bytecode (.class)
 
314
          files. However, in many cases the native code produced by
 
315
          compiling from source is better optimized than that compiled
 
316
          from .class files.
 
317
 
 
318
          Per Bothner explains:
 
319
 
 
320
            The reason is that when you compile to bytecode you lose a
 
321
            lot of information about program structure etc. That
 
322
            information helps in generating better code. We can in
 
323
            theory recover the information we need by analysing the
 
324
            structure of the bytecodes, but it is sometimes difficult
 
325
            - or sometimes it just that no-one has gotten around to
 
326
            it.  Specific examples include loop structure (gcc
 
327
            generates better code with explicit loops rather than with
 
328
            the equivalent spaghetti code), array initializers, and
 
329
            the JDK 1.1 `CLASS.class' syntax, all of which are
 
330
            represented using more low-level constructs in bytecode.
 
331
 
 
332
      4.3 "gcj -C" Doesn't seem to work like javac/jikes.  Whats going on?
 
333
 
 
334
          The behavior of "gcj -C" is not at all like javac or jikes,
 
335
          which will compile (not just scan) all .java's which are out
 
336
          of date with regard to their .class's.
 
337
 
 
338
      4.4 Where does GCJ look for files?
 
339
 
 
340
          GCJ looks for classes to compile based on the CLASSPATH
 
341
          environment variable. libgcj.jar and other files are found
 
342
          relative to the path of the compiler itself, so it is safe
 
343
          to move the entire compiler tree to a different path, and
 
344
          there is no need to include libgcj.jar in your CLASSPATH.
 
345
 
 
346
      4.5 How does gcj resolve whether to compile .class or .java files?
 
347
 
 
348
          GCJ compiles only the files presented to it on the command
 
349
          line. However, it also needs to scan other files in order to
 
350
          determine the layout of other classes and check for errors
 
351
          in your code.  For these dependencies, GCJ will favour
 
352
          .class files if they are available because it is faster to
 
353
          parse a class file than source code.
 
354
 
 
355
      4.6 I'm getting link errors
 
356
 
 
357
          If you get errors at link time that refer to 'undefined
 
358
          reference to `java::lang::Object type_info function', verify
 
359
          that you have compiled any CNI C++ files with the -fno-rtti
 
360
          option. This is only required for versions of GCJ earlier
 
361
          than 3.0.
 
362
 
 
363
      4.7 I'm getting 'undefined symbol: __dso_handle'
 
364
 
 
365
          Some versions of the GNU linker have broken support for the
 
366
          '.hidden' directive, which results in problems with shared
 
367
          libraries built with recent versions of gcc.
 
368
 
 
369
          There are three solutions:
 
370
 
 
371
            - downgrade to binutils that don't support .hidden at all,
 
372
            - upgrade to a recent binutils, or
 
373
            - undef the HAVE_GAS_HIDDEN definition in gcc's auto-host.h
 
374
              (and rebuild gcc).
 
375
 
 
376
Runtime Questions
 
377
=================
 
378
 
 
379
      5.1 My program is dumping core! What's going on?
 
380
 
 
381
          It could be any number of things. One common mistake is
 
382
          having your CLASSPATH environment variable pointing at a
 
383
          third party's java.lang and friends. Either unset CLASSPATH,
 
384
          or make sure it does not refer to core libraries other than
 
385
          those found in libgcj.jar.Note that newwer versions of GCJ
 
386
          will reject the core class library if it wasn't generated by
 
387
          GCJ itself.
 
388
 
 
389
      5.2 When I run the debugger I get a SEGV in the GC! What's going on?
 
390
 
 
391
          This is "normal"; the Garbage Collector (GC) uses it to
 
392
          determine stack boundaries. It is ordinarily caught and
 
393
          handled by the GC -- you can see this in the debugger by
 
394
          using cont to continue to the "real" segv.
 
395
 
 
396
      5.3 I have just compiled and benchmarked my Java application
 
397
          and it seems to be running slower than than XXX JIT JVM. Is there
 
398
          anything I can do to make it go faster?
 
399
 
 
400
        A few things:
 
401
 
 
402
          - If your programs allocate many small, short lived objects,
 
403
            the heap could be filling and triggering GC too
 
404
            regularly. Try increasing the initial and maximum heap sizes
 
405
            as per 5.5 How do I increase the runtime's initial and
 
406
            maximum heap size?
 
407
          - RE - array accesses. We have sub-optimal runtime checking
 
408
            code, and the compiler is still not so smart about
 
409
            automatically removing array checks. If your code is ready,
 
410
            and it doesn't rely on them, try compiling with
 
411
            --no-bounds-check.
 
412
          - Try static linking.  On many platforms, dynamic (PIC)
 
413
            function calls are more expensive than static ones. In
 
414
            particular, the interaction with boehm-gc seems to incur
 
415
            extra overhead when shared libraries are used.
 
416
          - If your Java application doesn't need threads, try
 
417
            building libgcj using --enable-threads=none. Portions of the
 
418
            libgcj runtime are still more efficient when
 
419
            single-threaded.
 
420
 
 
421
       5.4 Can I profile Garbage Collection?
 
422
 
 
423
          It is possible to turn on verbose GC output by supressing
 
424
          the -DSILENT flag during build. One way to do this is to
 
425
          comment out the line with #define SILENT 1 from
 
426
          boehm-gc/configure before configuring libgcj.  The GC will
 
427
          print collection statistics to stdout. (Rebuilding boehm-gc
 
428
          alone without this flag doesn't seem to work.)
 
429
 
 
430
      5.5 How do I increase the runtime's initial and maximum heap sizes?
 
431
 
 
432
          Some programs that allocate many small, short-lived objects
 
433
          can cause the default-sized heap to fill quickly and GC
 
434
          often. With the 2.95.1 release there is no means to adjust
 
435
          the heap at runtime. Recent snapshots provide the -ms and
 
436
          -mx arguments to gij to specify the initial and maximum heap
 
437
          sizes, respectively.
 
438
 
 
439
      5.6 How can I profile my application?
 
440
 
 
441
          Currently, only single threaded Java code may be used by the
 
442
          profiler (gprof). POSIX threads seem to be incompatible with
 
443
          the gmon stuff.  A couple of other tools that have been
 
444
          mentioned on the GCJ mailing list are sprof and cprof.  The
 
445
          former is part of GNU libc.
 
446
 
 
447
      5.7 My program seems to hang and doesn't produce any output
 
448
 
 
449
          Some versions had a bug in the iconv support. You can work
 
450
          around it by setting LANG=en_US.UTF-8 at runtime, or give
 
451
          the following option during compile time
 
452
          -Dfile.encoding=UTF-8.  This problem should no longer occur
 
453
          as of November 1, 2000.
 
454
 
 
455
Programming Issues
 
456
==================
 
457
 
 
458
      6.1 Are there any examples of how to use CNI?
 
459
 
 
460
          Glenn Chambers has created a couple of trivial examples for
 
461
          version 2.95 and version 3.0.  As a comparison, here is the
 
462
          same example as a JNI application using Kaffe.  The same
 
463
          code will work with GCJ, as shown here.
 
464
 
 
465
          Note that for version 2.95, you must compile the C++ files
 
466
          used for CNI with the -fno-rtti option.  This constraint
 
467
          does not apply in version 3.0 and later.
 
468
 
 
469
          The primary source of documentation for CNI is at
 
470
          http://gcc.gnu.org/java/papers/cni/t1.html
 
471
 
 
472
      6.2 Is it possible to invoke GCJ compiled Java code from a
 
473
          C++ application?
 
474
 
 
475
          Yes, GCJ 3.1 supports a CNI-based invocation interface as
 
476
          well as the traditional JNI invocation API.  See the GCJ
 
477
          Manual for more details on how to use the CNI interface.
 
478
 
 
479
Please send FSF & GNU inquiries & questions tognu@gnu.org.There are
 
480
also other waysto contact the FSF.
 
481
 
 
482
These pages are maintained by The GCC team.
 
483
 
 
484
Please send comments on these web pages and GCC to our publicmailing
 
485
list at gcc@gnu.org orgcc@gcc.gnu.org, send other questions to
 
486
gnu@gnu.org.
 
487
 
 
488
Copyright (C) Free Software Foundation, Inc.,
 
489
59 Temple Place - Suite 330, Boston, MA  02111,  USA.
 
490
 
 
491
Verbatim copying and distribution of this entire article is permitted
 
492
in any medium, provided this notice is preserved.
 
493
 
 
494
Last modified 2003-04-30