EXECUTION
Initialization: Implications for Code Generation
12.4.3
8. Next, execute either the class variable initializers and static initializers of the
class, or the field initializers of the interface, in textual order, as though they
were a single block, except that
final
class variables and fields of interfaces
whose values are compile time constants are initialized first ( 8.3.2.1, 9.3.1,
13.4.8).
9. If the execution of the initializers completes normally, then lock this
Class
object, label it fully initialized, notify all waiting threads ( 20.1.10), release
the lock, and complete this procedure normally.
10. Otherwise, the initializers must have completed abruptly by throwing some
exception
E
. If the class of
E
is not
Error
or one of its subclasses, then create
a new instance of the class
ExceptionInInitializerError
, with
E
as the
argument, and use this object in place of
E
in the following step. But if a new
instance of
ExceptionInInitializerError
cannot be created because an
OutOfMemoryError
occurs, then instead use an
OutOfMemoryError
object in
place of
E
in the following step.
11. Lock the
Class
object, label it erroneous, notify all waiting threads
( 20.1.10), release the lock, and complete this procedure abruptly with reason
E
or its replacement as determined in the previous step.
(Due to a flaw in some early implementations of Java, a exception during class ini
tialization was ignored, rather than causing an
ExceptionInInitializerError
as described here.)
12.4.3 Initialization: Implications for Code Generation
Code generators need to preserve the points of possible initialization of a class or
interface, inserting an invocation of the initialization procedure just described. If
this initialization procedure completes normally and the
Class
object is fully ini
tialized 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 patch
ing 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 initialization
order for a group of related types can be determined. Such analysis must, how
ever, fully account for the fact that Java is concurrent and that initialization code is
unrestricted.
227
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved