This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Java name-mangling
- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: Java name-mangling
- From: Per Bothner <per at bothner dot com>
- Date: 09 Jun 2000 22:56:36 -0700
- Cc: gcc at gcc dot gnu dot org
- References: <20000609205048Y.mitchell@codesourcery.com>
I can think of these options:
(1) Use some simplified mangling for classes declared extern "Java"
and either duplicate the algorithms (for both jc1 and cc1plus) or
put the code in a shared file.
(2) Ditto, but key off whether the type has the Java attribute
(basically, whetehr a method inherits from java::lang::Object).
(3) Re-implement in jc1 the subset of C++ mangling that Java needs.
(4) Have jc1 link in the same file that cc1plus uses for mangling.
This is cp/mangle.c - though moving that file to some other directory
may make sense.
I think option (4) is preferable, but the problem is that mangle.c
depends on various cc1plus definitions. However, if we compile
mangle.c is its cp context, and just link in the .o file, it
doesm't look too bad. I did a nm -u mangle.o, and the list was
actually quite short, once you subtract out functions and variables
not c++ specific. It seems like it should be easy to just write dummy
definitions in gcc/java of those few functions and variables.
> Java folks, what are you guys planning with respect to the new ABI
> for GCC 3.0? There are issues with layout as well as name-mangling,
> including vtable layout.
I can't answer for teh "Java folks", as I not actively involved.
However, the orginal philosophy was that Java would use an appropriate
subset of the C++ ABI, to the extent practical. I would assume
implementing compatible vtables would be easy, as Java does not have
multiple inheritance in the C++ sense, but I don't know the new
vtable format.
Gcj implements a special kind of vtables to handle Java interfaces,
which I think of as a special case of multiple inheritance
restricted to abstract virtual base classes with no instance fields.
Java uses tables to allow constant-time interface calls, without
adjusting the this pointer. I've mentioned this here before, and
also the possibility that C++ could possibly use the same algorithm
for the special case of no-field abstract virtual bases. The Java
algorithm is slightly slower than the traditional C++ implementation,
but you don't need extra per-object vbase pointers or extra vtables,
and you don't need to adjust the this pointer. The standard C++
implementation of virtual base classes is undesirable for Java,
because we don't want to have to adjust the this pointer. (Technically,
adjusting the this pointer violates the Java Virtual Machine spec.
It may be possible but painful to work around this.)
--
--Per Bothner
per@bothner.com http://www.bothner.com/~per/