class initialization check overhead
Kresten Krab Thorup
krab@trifork.com
Thu Oct 24 01:18:00 GMT 2002
How about using a pattern such as:
----------------------
// file-scope
int _init_gnu_foo_MyClass __attribute__((common));
extern _JvClass _gnu_foo_MyClass;
// inside method code
{
...
if (!_initialized_org_gnu_foo_MyClass) {
_Jv_InitClass(&_gnu_foo_MyClass, &_init_gnu_foo_MyClass;);
}
...
}
-----------------------
The _init_xxx variables could be defined as "common" so multiple
occurrences would turn into one (and default to a 0 value). [yes, I
know there is no such attribute defined, I just put it there to
illustrate my point] Or we can use some other linker trick the platform
supports for obtaining this effect.
The implementation of _Jv_InitClass would then do something like this:
------------------------
void _Jv_InitClass(_JvClass* clazz, int *callee_class_initialized)
{
if (!clazz->isInitialized) {
.. do the normal initialization ...
clazz->isInitialized = TRUE;
}
*callee_class_initialized = TRUE;
}
-----------------------
This way, we would also avoid spilling registers if the class is in fact
already initialized.
It seems to me that this would be more portable than using traps.
Kresten
Adam Megacz wrote:
> Jeff Sturm <jsturm@one-point.com> writes:
>>>Not without doing away with the calling convention, CALL_EXPR, etc.
>>> Is this because there's no way to construct a java/c++ tree that
> translates into a bare CALL without breaking abstraction barriers? I
> could see how that might be the case.
>>>>>Some trapping instruction might be better, like below. This example only
>>clobbers eax and memory, and overwrites the single-byte INT3 with one NOP.
>>> Very cool... would this work for references to static members as well?
>> - a
>>
More information about the Java
mailing list