Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > "Small" Program Challenge.

Reply
Thread Tools

"Small" Program Challenge.

 
 
javax.swing.JSnarker
Guest
Posts: n/a
 
      06-23-2012
On 23/06/2012 7:42 AM, Wanja Gayk wrote:
> In article <jrts0t$55e$(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed)
> says...
>
>> Which would contravene the spec, since the spec clearly says that
>> initialization must *precede* invocation.

>
> Between loading and initialization theres still verification, isn't it?


Verification is a part of loading, rather than coming after it.

--
public final class JSnarker
extends JComponent
The JSnarker is an NNTP-aware component that asynchronously provides
snarky output when the Ego.needsPuncturing() event is fired in cljp.


 
Reply With Quote
 
 
 
 
javax.swing.JSnarker
Guest
Posts: n/a
 
      06-23-2012
On 23/06/2012 5:10 PM, Wanja Gayk wrote:
> In article <js4psp$59p$(E-Mail Removed)>, (E-Mail Removed)
> says...
>>
>> On 23/06/2012 7:42 AM, Wanja Gayk wrote:
>>> In article <jrts0t$55e$(E-Mail Removed)>, (E-Mail Removed)
>>> says...
>>>
>>>> Which would contravene the spec, since the spec clearly says that
>>>> initialization must *precede* invocation.
>>>
>>> Between loading and initialization theres still verification, isn't it?

>>
>> Verification is a part of loading, rather than coming after it.

>
> I'm curious: How do you want to verify something that you haven't loaded
> yet?


I don't. Neither do I want a loaded class hanging around unverified
afterward, though. So the two belong back-to-back. Essentially,
obtaining the byte code from wherever into main memory is step 1 of
loading, and verifying it is step 2.

--
public final class JSnarker
extends JComponent
A JSnarker is an NNTP-aware component that asynchronously provides
snarky output when the Ego.needsPuncturing() event is fired in cljp.


 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      06-25-2012
javax.swing.JSnarker wrote:
> Daniel Pitts wrote:
>> How I would expect this to work in reality.
>>
>> 1. Load class
>> 2. get a reference to the static method "void main(String[])"
>> 3. Attempt to execute that reference
>> 3.1 Causes class initialization before execution.
>> 3.2 actual execution occurs.

>
> That has a problem, though, in that class initialization will happen on
> every method call, resulting in multiple initializations, if it's part


That's not what happens.

> of "attempt to execute the reference" rather than (as the spec says)
> something the JVM does immediately *before* the first such attempt (or
> other action that requires an initialized class for the action to begin).


As the spec says, it happens upon the first attempt to execute a static method
(if the class has not already been initialized).

> I suppose you could change 3.1 to "see if the class is initialized, and
> if not, initialize it", but even that would add to *every method call*


That is what the spec says to do. As previously linked.

> the overhead of a test-and-branch, and would still be dodgy at best on
> spec-adherence grounds.


No, it does what it does and adheres to the spec.

See the previously linked references for the details.

--
Lew
 
Reply With Quote
 
javax.swing.JSnarker
Guest
Posts: n/a
 
      06-25-2012
On 25/06/2012 3:59 PM, Lew wrote:
> javax.swing.JSnarker wrote:
>> Daniel Pitts wrote:
>>> How I would expect this to work in reality.
>>>
>>> 1. Load class
>>> 2. get a reference to the static method "void main(String[])"
>>> 3. Attempt to execute that reference
>>> 3.1 Causes class initialization before execution.
>>> 3.2 actual execution occurs.

>>
>> That has a problem, though, in that class initialization will happen on
>> every method call, resulting in multiple initializations, if it's part

>
> That's not what happens.


I'm not finished. Class initialization will happen on every method call,
resulting in multiple initializations, *if it's part* of "attempt to
execute the reference" rather than (as the spec says) something the JVM
does immediately *before* the first such attempt (or other action that
requires an initialized class for the action to begin).

> As the spec says, it happens upon the first attempt to execute a static method
> (if the class has not already been initialized).


No, the spec does not say "upon" it says "immediately before".

>> I suppose you could change 3.1 to "see if the class is initialized, and
>> if not, initialize it", but even that would add to *every method call*

>
> That is what the spec says to do. As previously linked.
>
>> the overhead of a test-and-branch, and would still be dodgy at best on
>> spec-adherence grounds.

>
> No, it does what it does and adheres to the spec.


No, what the spec says to do is to implement a statically-compiled call
this way:

Class is loaded and initialized by statically-compiled code.
Method invocation is simply a bare invokestatic instruction

And a reflective/otherwise non-static call this way:

Check if class is loaded and if not load and verify it.
Check if class is initialized and if not initialize it.
Check if method exists and if not throw an exception, otherwise invoke it.

And this is apparently what earlier versions did.

Surely you aren't suggesting there's a whole raft of if
(class_is_loaded), if (class_is_initialized), etc. tests before every
method call in Java 7? Because that would make method calls much slower
than before, unless you've got some cleverness in place to remove those
tests from the code once the class is loaded. In other words, something
more like expanding each call into

load_and_initialize_if_needed(X.class);
invokestatic...

where load_and_initialize_if_needed(X.class) strips out all instances of
load_and_initialize_if_needed(X.class) from all loaded bytecode as part
of its own behavior. But that would have all kinds of difficulties of
its own. At least the JIT might be able to skip over it if X is already
loaded and an instance is in code it's JITting.

--
public final class JSnarker
extends JComponent
A JSnarker is an NNTP-aware component that asynchronously provides
snarky output when the Ego.needsPuncturing() event is fired in cljp.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to javac a java program w/ another java program which is w/o a main method cjeffwang@yahoo.com Java 1 10-31-2005 04:25 AM
System program/ Application program ?? Parvsandhu Java 2 07-11-2005 09:08 AM
how to convert a java program to an exe program ola Java 3 02-16-2004 09:42 AM
Calling Java program in another Java program Rey Java 4 12-12-2003 10:18 PM
passing data between Java program and C program--help pipi Java 1 07-21-2003 05:02 AM



Advertisments