Java Reference
In-Depth Information
stance of the class ExceptionInInitializerError , with E as the argument, and use this ob-
ject in place of E in the following step. But if a new instance of ExceptionInInitializer-
Error cannot be created because an OutOfMemoryError occurs, then instead use an
OutOfMemoryError object in place of E in the following step.
12. Acquire LC , label the Class object for C as erroneous, notify all waiting threads, re-
lease LC , and complete this procedure abruptly with reason E or its replacement as
determined in the previous step.
An implementation may optimize this procedure by eliding the lock acquisi-
tion in step 1 (and release in step 4/5) when it can determine that the initializa-
tion of the class has already completed, provided that, in terms of the memory
model, all happens-before orderings that would exist if the lock were acquired,
still exist when the optimization is performed.
Code generators need to preserve the points of possible initialization of a class
or interface, inserting an invocation of the initialization procedure just de-
scribed. If this initialization procedure completes normally and the Class object
is fully initialized and ready for use, then the invocation of the initialization
procedure is no longer necessary and it may be eliminated from the code - for
example, by patching it out or otherwise regenerating the code.
Compile-time analysis may, in some cases, be able to eliminate many of the
checks that a type has been initialized from the generated code, if an initializa-
tion order for a group of related types can be determined. Such analysis must,
however, fully account for concurrency and for the fact that initialization code
is unrestricted.
12.5. Creation of New Class Instances
A new class instance is explicitly created when evaluation of a class instance creation ex-
pression (§ 15.9 ) causes a class to be instantiated.
A new class instance may be implicitly created in the following situations:
• Loading of a class or interface that contains a String literal (§ 3.10.5 ) may create a
new String object to represent that literal. (This might not occur if the same String
has previously been interned (§ 3.10.5 ).)
• Execution of an operation that causes boxing conversion (§ 5.1.7 ) . Boxing conver-
sion may create a new object of a wrapper class associated with one of the primit-
ive types.
Search WWH ::




Custom Search