Reputation: 1137
In my journey to understand programming languages/compilers, I thought it might be cool to try to write small versions of the Java class library.
I decided to start with writing my own println() method. And no, not a method that simply calls println.
My Code so far:
package maintest;
import java.io.PrintStream;
import gnu.classpath.SystemProperties;
import gnu.classpath.VMStackWalker;
public class JohnSystem {
public static final PrintStream out = VMSystem.makeStandardOutputStream();
}
So basically, I wrote a "new" System class. Now something funny I noticed about the OpenJDK system class. The public static final
variable 'out' contained within Java.lang.System
doesn't get instantiated in the way objects normally do with the new keyword. I tried to mimic the way it was done and wrote the code above accordingly.
I figured VMSystem
was another class in the class library which had a static method makeStandardOutputStream()
which returned a PrintStream
object.
That would be fine except the compiler (or maybe eclipse?) doesn't recognize VMSystem and when I tried to import the packages I found at the OpenJDK, they are also not recognized.
The code I'm referring to is at: http://developer.classpath.org/doc/java/lang/System-source.html
So, basically I'm trying to find out how to be able to use the VMSystem methods. Is there maybe a package I need to download? That doesn't really make sense though. Since System.out.println()
works, then the packages must already be there no? Or is it perhaps a permissions/security issue?
Thanks!
Upvotes: 0
Views: 297
Reputation: 718708
The VMSystem
class is an internal class in the (old, virtually defunct) GNU ClassPath implementation of the Java SE class libraries.
It is not part of the Java APIs, and there is no equivalent to it in OpenJDK; i.e. the methods you are looking for may not exist.
On the other hand ... if you want to understand how OpenJDK handles JVM bootstrapping (setting up in
, out
and err
for example), your best bet is to download an actual OpenJDK source tree, and deep-dive it.
In Java 11 for example, the initialization of in
, out
and err
happens in a private method of System
called initPhase1()
. Naturally, you can't call it (because it is private
), but you can certainly look to see what it does and duplicate that in your own experiment. But you will see that the actual assignment of the those variables happens in native code.
Finally:
In my journey to understand programming languages/compilers, I thought it might be cool to try to write small versions of the Java class library.
I think you would be better of just reading the OpenJDK source code.
Upvotes: 2