You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Weldon Washburn <we...@gmail.com> on 2006/03/09 00:49:36 UTC

[jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Archie,

I can now run the below multithread Hello.java on JCHEVM using Apache
Harmony Class Library.  The output toggles between clumps of "Hello
World" and clumps of "*" as WindowsXP schedules the two application
threads.  This is behavior I would expect. I use System.out.write()
because System.out.println() does not work yet.   A summary follows:

Mods to JCHEVM to get it to work
1)
I was not able to find the _JC_LIB_ENTRY that is intended for
read/writing files.  I gave up and "borrowed"
JCNI_java_lang_VMThread_nativeSetPriority().  Instead of actually
changing thread priority, it now does a "fprintf(stdout, "%s",
&priority); fflush(stdout);"  Perhaps you can tell me what native
method I should be using.
2)
I commented out some stuff in bootstrap.c that was dragging in
specific gnu classpath *.class files like "Lgnu/classpath/Pointer;" 
We should discuss the best solution for this item.

Harmony Class Lib that were modified to get it to work:
Runtime.java -- expected "wrapper" code. e.g., add VMRuntime.exit() to
Runtime.exit()
Method.java, Field.java, Constructor.java -- minor mods
System.java -- added VMSystem.setOut, setErr... etc
ThreadGroup.java  -- wrappers
Class.java  -- wrappers
Object.java -- wrappers
String.java -- implemented a very simple intern()
Thread.java -- added a bunch of fields that JCHEVM accesses, added
code to start() to create ThreadGroup.root if it does not already
exist
Throwable.java  -- wrappers
ClassLoader.java -- commented out "abstract" keyword on class
definition (too lazy to create a sub-class), added fields that JCHEVM
accesses, added code getSystemClassLoader to actually create an object
and stuff it in systemClassLoader if it does not already exist. added
a bunch of wrapper code.
OSMemory -- hacked out a bunch of stuff that was in the way
OSFileSystem -- add an ugly hack in writeImpl() to revector chars to
Thread.setPriority()

One last item.  I don't know which SVN repository to place this work
in.  Any suggestions?

   Thanks
       Weldon

##########################

class Hello extends Thread {

public static void main(String args[])
{

   byte [] ba = new byte[64];

   ba [0] = 'H'; ba [1] = 'e'; ba [2] = 'l'; ba [3] = 'l'; ba [4] = 'o';

   ba [5] = ' '; ba [6] = 'W'; ba [7] = 'o'; ba [8] = 'r'; ba [9] =
'l';  ba[10] = 'd'; ba[11] = ' ';


   Thread tr = new Hello();
   tr.start();	

   while (true) {
      for (int qq = 0; qq < 12; qq++) {
            System.out.write(ba[qq]);
      }

    }

}
public void run() {
    while(true) {
      System.out.write('*');
    }
}
}

--
Weldon Washburn
Intel Middleware Products Division

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Archie Cobbs <ar...@dellroad.org>.
Weldon Washburn wrote:
>> Classpath supplies its own native methods for file I/O. That is,
>> you can implement file I/O normally using normal native methods.
>> This is not something the VM needs to be directly involved with.
>> So the "fix" would be for classlib to implement this itself.
> 
> I suspected this.  But I could not figure out how to add a new entry
> into _JC_LIB_ENTRY.  I tried but got a bunch of misc error messages so
> I gave up.  If you give me some hints on how to add enties to
> _JC_LIB_ENTRY, I will take a second stab at it.

You would not modify that code (or any other part of jchevm) at all.
Instead, you'd build a JNI native library as part of classlib and
then load in your Java code it via System.loadLibrary(). This is just
the usual "Java code with native library" pattern.

The _JC_LIB_ENTRY() stuff is only for native methods that are provided
by jchevm itself, e.g., java.lang.VMThread.start(), Runtime.gc(), etc.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Tim Ellison <t....@gmail.com>.
Weldon Washburn wrote:
> On 3/9/06, Archie Cobbs <ar...@dellroad.org> wrote:
>> Weldon Washburn wrote:
>>> I can now run the below multithread Hello.java on JCHEVM using Apache
>>> Harmony Class Library.  The output toggles between clumps of "Hello
>>> World" and clumps of "*" as WindowsXP schedules the two application
>>> threads.  This is behavior I would expect. I use System.out.write()
>>> because System.out.println() does not work yet.   A summary follows:
>> Wow! Impressive achievment & very cool.

Yes, very cool -- good work Weldon.

>>> Mods to JCHEVM to get it to work
>>> 1)
>>> I was not able to find the _JC_LIB_ENTRY that is intended for
>>> read/writing files.  I gave up and "borrowed"
>>> JCNI_java_lang_VMThread_nativeSetPriority().  Instead of actually
>>> changing thread priority, it now does a "fprintf(stdout, "%s",
>>> &priority); fflush(stdout);"  Perhaps you can tell me what native
>>> method I should be using.
>> Classpath supplies its own native methods for file I/O. That is,
>> you can implement file I/O normally using normal native methods.
>> This is not something the VM needs to be directly involved with.
>> So the "fix" would be for classlib to implement this itself.
> 
> I suspected this.  But I could not figure out how to add a new entry
> into _JC_LIB_ENTRY.  I tried but got a bunch of misc error messages so
> I gave up.  If you give me some hints on how to add enties to
> _JC_LIB_ENTRY, I will take a second stab at it.
> 
>> There's no reason you couldn't write a gnu.classpath.Pointer
>> class if you wanted to. There's no copyright on the package
>> name :-)
> 
> I just now wrote an Apache Harmony version of java.lang.Pointer and
> java.lang.Pointer32.  It works fine.  I put it in the
> Harmony/modules/kernel/src/main/java/java/lang directory.  It can be
> move to another place and "re-packaged" once we figure out where it
> should go.

Take a look at the PlatformAddress type and see if that already does
what you want.

http://svn.apache.org/viewcvs.cgi/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/struct/PlatformAddress.java?view=markup

>> By the way jchevm's Thread.setPriority() doesn't work because
>> I don't know how to implement it using POSIX.
>>
>>> 2)
>>> I commented out some stuff in bootstrap.c that was dragging in
>>> specific gnu classpath *.class files like "Lgnu/classpath/Pointer;"
>>> We should discuss the best solution for this item.
>> This is use as part of the NIO implementation for "direct" buffers.
>> A Pointer object simply contains an int or long that holds a void *.
>>
>>> One last item.  I don't know which SVN repository to place this work
>>> in.  Any suggestions?
>> You could create a branch of classlib in the "sandbox".
> 
> Tim Ellison, Geir Magnusson,
> I could create a ClassLib branch in the sandbox and call it
> "kernel_path".  It would only contain the generic files needed to glue
> a GNU ready JVM to Harmony Class Lib.  Thoughts?

AFAIK you only have read access across the whole repository, but you can
send it in via JIRA and somebody can drop it in for you.

Regards,
Tim

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Weldon Washburn <we...@gmail.com>.
On 3/9/06, Archie Cobbs <ar...@dellroad.org> wrote:
> Weldon Washburn wrote:
> > I can now run the below multithread Hello.java on JCHEVM using Apache
> > Harmony Class Library.  The output toggles between clumps of "Hello
> > World" and clumps of "*" as WindowsXP schedules the two application
> > threads.  This is behavior I would expect. I use System.out.write()
> > because System.out.println() does not work yet.   A summary follows:
>
> Wow! Impressive achievment & very cool.
>
> > Mods to JCHEVM to get it to work
> > 1)
> > I was not able to find the _JC_LIB_ENTRY that is intended for
> > read/writing files.  I gave up and "borrowed"
> > JCNI_java_lang_VMThread_nativeSetPriority().  Instead of actually
> > changing thread priority, it now does a "fprintf(stdout, "%s",
> > &priority); fflush(stdout);"  Perhaps you can tell me what native
> > method I should be using.
>
> Classpath supplies its own native methods for file I/O. That is,
> you can implement file I/O normally using normal native methods.
> This is not something the VM needs to be directly involved with.
> So the "fix" would be for classlib to implement this itself.

I suspected this.  But I could not figure out how to add a new entry
into _JC_LIB_ENTRY.  I tried but got a bunch of misc error messages so
I gave up.  If you give me some hints on how to add enties to
_JC_LIB_ENTRY, I will take a second stab at it.

>
> There's no reason you couldn't write a gnu.classpath.Pointer
> class if you wanted to. There's no copyright on the package
> name :-)

I just now wrote an Apache Harmony version of java.lang.Pointer and
java.lang.Pointer32.  It works fine.  I put it in the
Harmony/modules/kernel/src/main/java/java/lang directory.  It can be
move to another place and "re-packaged" once we figure out where it
should go.

>
> By the way jchevm's Thread.setPriority() doesn't work because
> I don't know how to implement it using POSIX.
>
> > 2)
> > I commented out some stuff in bootstrap.c that was dragging in
> > specific gnu classpath *.class files like "Lgnu/classpath/Pointer;"
> > We should discuss the best solution for this item.
>
> This is use as part of the NIO implementation for "direct" buffers.
> A Pointer object simply contains an int or long that holds a void *.
>
> > One last item.  I don't know which SVN repository to place this work
> > in.  Any suggestions?
>
> You could create a branch of classlib in the "sandbox".

Tim Ellison, Geir Magnusson,
I could create a ClassLib branch in the sandbox and call it
"kernel_path".  It would only contain the generic files needed to glue
a GNU ready JVM to Harmony Class Lib.  Thoughts?


>
> Cheers,
> -Archie
>
> __________________________________________________________________________
> Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
>


--
Weldon Washburn
Intel Middleware Products Division

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Archie Cobbs <ar...@dellroad.org>.
Weldon Washburn wrote:
> I can now run the below multithread Hello.java on JCHEVM using Apache
> Harmony Class Library.  The output toggles between clumps of "Hello
> World" and clumps of "*" as WindowsXP schedules the two application
> threads.  This is behavior I would expect. I use System.out.write()
> because System.out.println() does not work yet.   A summary follows:

Wow! Impressive achievment & very cool.

> Mods to JCHEVM to get it to work
> 1)
> I was not able to find the _JC_LIB_ENTRY that is intended for
> read/writing files.  I gave up and "borrowed"
> JCNI_java_lang_VMThread_nativeSetPriority().  Instead of actually
> changing thread priority, it now does a "fprintf(stdout, "%s",
> &priority); fflush(stdout);"  Perhaps you can tell me what native
> method I should be using.

Classpath supplies its own native methods for file I/O. That is,
you can implement file I/O normally using normal native methods.
This is not something the VM needs to be directly involved with.
So the "fix" would be for classlib to implement this itself.

There's no reason you couldn't write a gnu.classpath.Pointer
class if you wanted to. There's no copyright on the package
name :-)

By the way jchevm's Thread.setPriority() doesn't work because
I don't know how to implement it using POSIX.

> 2)
> I commented out some stuff in bootstrap.c that was dragging in
> specific gnu classpath *.class files like "Lgnu/classpath/Pointer;" 
> We should discuss the best solution for this item.

This is use as part of the NIO implementation for "direct" buffers.
A Pointer object simply contains an int or long that holds a void *.

> One last item.  I don't know which SVN repository to place this work
> in.  Any suggestions?

You could create a branch of classlib in the "sandbox".

Cheers,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Dalibor Topic <ro...@kaffe.org>.
On Fri, Mar 10, 2006 at 04:37:16AM -0800, Leo Simons wrote:
> On Wed, Mar 08, 2006 at 03:49:36PM -0800, Weldon Washburn wrote:
> > I can now run the below multithread Hello.java on JCHEVM using Apache
> > Harmony Class Library.
> 
> Cool!
> 

contratulations from my side as well, excellent work!

cheers,
dalibor topic

> > Runtime.java -- expected "wrapper" code. e.g., add VMRuntime.exit() to
> > Runtime.exit()
> > Method.java, Field.java, Constructor.java -- minor mods
> > System.java -- added VMSystem.setOut, setErr... etc
> > ThreadGroup.java  -- wrappers
> > Class.java  -- wrappers
> > Object.java -- wrappers
> > String.java -- implemented a very simple intern()
> > Thread.java -- added a bunch of fields that JCHEVM accesses, added
> > code to start() to create ThreadGroup.root if it does not already
> > exist
> > Throwable.java  -- wrappers
> > ClassLoader.java -- commented out "abstract" keyword on class
> > definition (too lazy to create a sub-class), added fields that JCHEVM
> > accesses, added code getSystemClassLoader to actually create an object
> > and stuff it in systemClassLoader if it does not already exist. added
> > a bunch of wrapper code.
> > OSMemory -- hacked out a bunch of stuff that was in the way
> > OSFileSystem -- add an ugly hack in writeImpl() to revector chars to
> > Thread.setPriority()
> > 
> > One last item.  I don't know which SVN repository to place this work
> > in.  Any suggestions?
> 
> First step is always to create a patch and put it in jira or send it to
> the mailing list.
> 
> I am guessing that with some additional work these kinds of changes can
> just go into the trunk/ for the respective source code?
> 
> - LSD

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Leo Simons <ma...@leosimons.com>.
On Wed, Mar 08, 2006 at 03:49:36PM -0800, Weldon Washburn wrote:
> I can now run the below multithread Hello.java on JCHEVM using Apache
> Harmony Class Library.

Cool!

> Runtime.java -- expected "wrapper" code. e.g., add VMRuntime.exit() to
> Runtime.exit()
> Method.java, Field.java, Constructor.java -- minor mods
> System.java -- added VMSystem.setOut, setErr... etc
> ThreadGroup.java  -- wrappers
> Class.java  -- wrappers
> Object.java -- wrappers
> String.java -- implemented a very simple intern()
> Thread.java -- added a bunch of fields that JCHEVM accesses, added
> code to start() to create ThreadGroup.root if it does not already
> exist
> Throwable.java  -- wrappers
> ClassLoader.java -- commented out "abstract" keyword on class
> definition (too lazy to create a sub-class), added fields that JCHEVM
> accesses, added code getSystemClassLoader to actually create an object
> and stuff it in systemClassLoader if it does not already exist. added
> a bunch of wrapper code.
> OSMemory -- hacked out a bunch of stuff that was in the way
> OSFileSystem -- add an ugly hack in writeImpl() to revector chars to
> Thread.setPriority()
> 
> One last item.  I don't know which SVN repository to place this work
> in.  Any suggestions?

First step is always to create a patch and put it in jira or send it to
the mailing list.

I am guessing that with some additional work these kinds of changes can
just go into the trunk/ for the respective source code?

- LSD

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Weldon Washburn <we...@gmail.com>.
On 3/9/06, Enrico Migliore <en...@fatti.com> wrote:
> Hi Weldon,
>
>  Well done!
>
>  Where did you actually run the test: Cygwin, Linux, or both?

I did all the work on Cygwin.  I ran out of time for installing vmware
and linux on my laptop.

>
> Enrico
>


--
Weldon Washburn
Intel Middleware Products Division

Re: [jchevm] Harmony Class Lib does "Hello World" on a GNU Classpath JVM

Posted by Enrico Migliore <en...@fatti.com>.
Weldon Washburn wrote:

>Archie,
>
>I can now run the below multithread Hello.java on JCHEVM using Apache
>Harmony Class Library.  The output toggles between clumps of "Hello
>World" and clumps of "*" as WindowsXP schedules the two application
>threads.  This is behavior I would expect. I use System.out.write()
>because System.out.println() does not work yet.   A summary follows:
>
>Mods to JCHEVM to get it to work
>1)
>I was not able to find the _JC_LIB_ENTRY that is intended for
>read/writing files.  I gave up and "borrowed"
>JCNI_java_lang_VMThread_nativeSetPriority().  Instead of actually
>changing thread priority, it now does a "fprintf(stdout, "%s",
>&priority); fflush(stdout);"  Perhaps you can tell me what native
>method I should be using.
>2)
>I commented out some stuff in bootstrap.c that was dragging in
>specific gnu classpath *.class files like "Lgnu/classpath/Pointer;" 
>We should discuss the best solution for this item.
>
>Harmony Class Lib that were modified to get it to work:
>Runtime.java -- expected "wrapper" code. e.g., add VMRuntime.exit() to
>Runtime.exit()
>Method.java, Field.java, Constructor.java -- minor mods
>System.java -- added VMSystem.setOut, setErr... etc
>ThreadGroup.java  -- wrappers
>Class.java  -- wrappers
>Object.java -- wrappers
>String.java -- implemented a very simple intern()
>Thread.java -- added a bunch of fields that JCHEVM accesses, added
>code to start() to create ThreadGroup.root if it does not already
>exist
>Throwable.java  -- wrappers
>ClassLoader.java -- commented out "abstract" keyword on class
>definition (too lazy to create a sub-class), added fields that JCHEVM
>accesses, added code getSystemClassLoader to actually create an object
>and stuff it in systemClassLoader if it does not already exist. added
>a bunch of wrapper code.
>OSMemory -- hacked out a bunch of stuff that was in the way
>OSFileSystem -- add an ugly hack in writeImpl() to revector chars to
>Thread.setPriority()
>
>One last item.  I don't know which SVN repository to place this work
>in.  Any suggestions?
>
>   Thanks
>       Weldon
>
>##########################
>
>class Hello extends Thread {
>
>public static void main(String args[])
>{
>
>   byte [] ba = new byte[64];
>
>   ba [0] = 'H'; ba [1] = 'e'; ba [2] = 'l'; ba [3] = 'l'; ba [4] = 'o';
>
>   ba [5] = ' '; ba [6] = 'W'; ba [7] = 'o'; ba [8] = 'r'; ba [9] =
>'l';  ba[10] = 'd'; ba[11] = ' ';
>
>
>   Thread tr = new Hello();
>   tr.start();	
>
>   while (true) {
>      for (int qq = 0; qq < 12; qq++) {
>            System.out.write(ba[qq]);
>      }
>
>    }
>
>}
>public void run() {
>    while(true) {
>      System.out.write('*');
>    }
>}
>}
>
>--
>Weldon Washburn
>Intel Middleware Products Division
>
>  
>
Hi Weldon,

 Well done!

 Where did you actually run the test: Cygwin, Linux, or both?

Enrico