running Java applications within kaffe (Re: [kaffe] shutdownHook changes broke the build)

Dalibor Topic robilad at yahoo.com
Wed Jul 9 00:25:01 PDT 2003


hi Guilhem,

I've just checked in a patch that fixed the remaining compilation problems for
me. It now builds fine for me, but the shutdown hook test still fails. 

My patch changed the compile method of kaffe/tools/compiler/Compiler_kjc and
Compiler_pizza classes to return false only when an exception occurs. But I
don't think that kjc or pizza always throw an exception before they fail to
compile some code, so my implementation of compile() smells funny ;) On the
other hand, I don't think there is a way to get the exit codes of applications
ra within kaffe as their calls to Runtime.exit() should shutdown the whole
virtual machine.

so could you try again with the latest set of sources, and check if it makes
things any better?

Anyway, I'm not sure if running several java applications within a single kaffe
instance is a good idea, as long as kaffe doesn't implement some of process
separation features from JanosVM. 

So for example, what happens when an application calls runtime.exit()? It
shouldn't shut down the whole machine, unless it's the only application
running. It shouldn't run the finalizers of objects not belonging to it, and
only run its own shutdown hooks. The exit code should be stored for later
retrieval. I assume Tim could come up with further pitfalls. ;)

The apperently simple, but slow & fat way out is to just use Runtime.exec to
start another instance of a JVM. What do you think?

cheers,
dalibor topic

--- Guilhem Lavaux <guilhem.lavaux at free.fr> wrote:
> Hi,
> 
> I have reversed one or two things concerning kaffe.lang.Application to bring 
> it back in CVS and added its functionality in java.lang.Runtime.exit. This 
> must be considered as a temporary patch to make kaffe works as I do not think
> 
> that kaffe.lang.Application creates an inner application really rightly (for 
> example I can only have one Application unless I want to mess everything in 
> the VM and Application cannot be multithreaded). Maybe this should be cleaned
> 
> up with a sort of kaffe.lang.ProcessGroup which contains all threads of a 
> sub-process and Application should be an object attribute of a Thread...
> 
> Regards,
> 
> Guilhem.
> 
> P.S.: Someone will need to re-add kaffe/lang/Application.java and 
> clib/native/Application.c
> 
> P.P.S: Apparently this patch compiles on my computer but ShutdownHookTest has
> 
> a problem while removing the "dummy" thread as it is executed during the 
> shutdown phase. I will have a look this evening...> Index:
libraries/clib/native/Makefile.am
> ===================================================================
> RCS file: /cvs/kaffe/kaffe/libraries/clib/native/Makefile.am,v
> retrieving revision 1.21
> diff -u -3 -p -r1.21 Makefile.am
> --- libraries/clib/native/Makefile.am	8 Jul 2003 23:48:24 -0000	1.21
> +++ libraries/clib/native/Makefile.am	9 Jul 2003 06:27:45 -0000
> @@ -16,6 +16,7 @@ IO_SRCS = \
>  		ObjectStreamClassImpl.c
>  
>  LANG_SRCS = \
> +		Application.c \
>  		Class.c \
>  		ClassLoader.c \
>  		Compiler.c \
> Index: libraries/javalib/Klasses.jar.bootstrap
> ===================================================================
> RCS file: /cvs/kaffe/kaffe/libraries/javalib/Klasses.jar.bootstrap,v
> retrieving revision 1.20
> diff -u -3 -p -r1.20 Klasses.jar.bootstrap
> Binary files /tmp/cvswwpqJy and Klasses.jar.bootstrap differ
> Index: libraries/javalib/essential.files
> ===================================================================
> RCS file: /cvs/kaffe/kaffe/libraries/javalib/essential.files,v
> retrieving revision 1.11
> diff -u -3 -p -r1.11 essential.files
> --- libraries/javalib/essential.files	8 Jul 2003 23:48:25 -0000	1.11
> +++ libraries/javalib/essential.files	9 Jul 2003 06:27:52 -0000
> @@ -283,6 +283,7 @@ kaffe/io/StdErrorStream.java
>  kaffe/io/StdInputStream.java
>  kaffe/io/StdOutputStream.java
>  kaffe/lang/AppClassLoader.java
> +kaffe/lang/Application.java
>  kaffe/lang/ApplicationException.java
>  kaffe/lang/ApplicationResource.java
>  kaffe/lang/ClassPathReader.java
> Index: libraries/javalib/java/lang/Runtime.java
> ===================================================================
> RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/lang/Runtime.java,v
> retrieving revision 1.24
> diff -u -3 -p -r1.24 Runtime.java
> --- libraries/javalib/java/lang/Runtime.java	8 Jul 2003 23:48:25 -0000	1.24
> +++ libraries/javalib/java/lang/Runtime.java	9 Jul 2003 06:27:52 -0000
> @@ -101,10 +101,18 @@ public void exit(int status) throws Secu
>  	if (sm != null)
>  		sm.checkExit(status);
>  
> -	/* First we cleanup the Virtual Machine */
> -	exitJavaCleanup();
> -	/* Now we run the VM exit function */
> -	exit0(status);
> +	// Handle application extensions - if this thread is part of an
> +	// application then we exit that rather than the whole thing.
> +	if (!kaffe.lang.Application.exit(status)) {
> +		/* First we cleanup the Virtual Machine */
> +		exitJavaCleanup();
> +		/* Now we run the VM exit function */
> +		exit0(status);
> +	}
> +	// kaffe.lang.Application.exit does not destroy the thread
> +	// that invoked exit().  We stop that thread now.
> +	Thread.currentThread().destroy();
> +
>  }
>  
>  public void halt(int status) throws SecurityException {
> Index: libraries/javalib/java/lang/Thread.java
> ===================================================================
> RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/lang/Thread.java,v
> retrieving revision 1.41
> diff -u -3 -p -r1.41 Thread.java
> --- libraries/javalib/java/lang/Thread.java	8 Jul 2003 23:48:25 -0000	1.41
> +++ libraries/javalib/java/lang/Thread.java	9 Jul 2003 06:27:52 -0000
> @@ -13,6 +13,7 @@ package java.lang;
>  import java.util.HashMap;
>  import java.util.Iterator;
>  import java.security.AccessController;
> +import kaffe.lang.Application;
>  import kaffe.lang.ApplicationResource;
>  
>  public class Thread
> @@ -90,7 +91,9 @@ public Thread(ThreadGroup group, Runnabl
>  	this.group.checkAccess();
>  	this.group.add(this);
>  
> +	// make sure this.name is non-zero before calling addResource
>  	this.name = name.toCharArray();
> +	Application.addResource(this);
>  	this.target = target;
>  	this.interrupting = false;
>  
> @@ -160,6 +163,7 @@ public void destroy() {
>  	if (group != null) {
>  		group.remove(this);
>  	}
> +	Application.removeResource(this);
>  	destroy0();
>  }
>  
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com




More information about the kaffe mailing list