Initialization of static data in Java

Jon Olson olson@mmsi.com
Fri Nov 20 07:35:00 GMT 1998


On 1998年11月19日, Brian Miller wrote:
>Jon Olson wrote:
>>>> Without the `final', the compiler could just maintain a reference
>> within the object that gets overridden by subclasses.
>>I'm not sure exactly what optimization is being claimed here. Note
>that a final array's elements are not final. This is akin to C++'s
>" * const ", not C++'s " const * ".

Compiling Character.class with a -O2 will inevitably run out of
virtual memory; with -O, it achieves a RSS of about 60 megs
on my Linux x86 before finally finishing. Without optimization,
it compiles without much complaint, but the resulting code is
quite bad.
Nonetheless, I'm just giving it as an example. Not that I'd actually
use Sun's Character.class for anything, but it's a good torture test
for gcj at this point.
I recognize that Java has no concept of const data, just const references.
Note that without a final, you have the C++ equivalent of:
	struct Array { int count, void *data};
	Array *x;
With a final, you have the C++ equivalent of:
	Array *const x;
If the compiler can prove that the contents of `x' never get modified, then
is free to put `x's data table in read-only memory. If not, it must put it
in the `.data' segment. Seems to me that either way, however, it can
be initialized statically if it's declared `static' in Java.
Only thing you have to insure is that the GC doesn't try to garbage collect
static data tables. Not very difficult since conservative GCs know the address
range of the heap.
--
Jon Olson, Modular Mining Systems
	 3289 E. Hemisphere Loop
	 Tucson, AZ 85706
INTERNET: olson@mmsi.com
PHONE: (520)746-9127
FAX: (520)889-5790


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /