This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: WIN-28: fix POSIX file descriptor numbering assumptions


Adam Megacz wrote:

>Bryce McKinlay <bryce@waitaki.otago.ac.nz> writes:
>
>>How about putting the initialization of in/out/err into a native method 
>>and calling it from a static initializer, ie:
>>
>>static
>>{
>>  initNative();
>>}
>>
>
>I tried this -- unfortunately java.lang.System's <clinit> runs first,
>and it read the not-yet-initialized values out of
>FileDescriptor.{in|out|err} and crash trying to build a 'new
>PrintStream(null)'.
>

Huh? This can't happen. The language guarantees that a class is 
initialized before accessing its static fields. The only exceptions are:

- initializers which are somehow mutally dependent (they arn't in this case)
- field access from native (CNI) code, in which case an explicit 
JvInitClass() call is needed

>If you initialize to 'new FileDescriptor(getFdFOO())', the compiler
>figures out that it has to execute that code before it lets
>System.java access the variable. I don't know why this happens.
>

The compiler must execute all static initializer code before accessing a 
static field from a class. If it doesn't then there is a compiler bug.

regards

Bryce.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]