WebStart, VM options & J2D

Hi,

I want to be able to set some of these:
-Dsun.java2d.translaccel=true
-Dsun.java2d.ddforcevram=true
-Dsun.java2d.opengl=True

but WebStart doesn’t let you, it only allows those given here: http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/syntax.html#resources.

Before using WebStart I have been using System.exec(…) to restart a new VM with options however this doesn’t work with WebStart since I can’t find where the bin/java.exe file is. How can you set these options from WebStart? The JOGL guys must do it somehow since they need to set -Dsun.java2d.opengl=True. But how?

Thanks,
Keith

PS: Below is the code I used to use that no longer works with WebStart

public static void executeOptionedVM(boolean enableServerVM,
									boolean enableOpenGL,
									boolean enableCMSGC,
									boolean enableDDScale,
									boolean enableLargeMaxHeap,
									boolean enableTranslAccel,
									boolean enableDDForceVRAM,
									boolean enableNoddraw) throws java.io.IOException, SecurityException{
				String fileSeparator = System.getProperty("file.separator");
				String classPathOption = "-classpath"+" "+"\""+System.getProperty("java.class.path")+"\""; 
				// the above is the problem, it returns deploy.jar in WebStart, not the actual classpath

				System.out.println("System.getProperty(java.class.path)"+System.getProperty("java.class.path"));

				String serverVMOption = "-server";
				String openGLOption = "-Dsun.java2d.opengl=True";
				String cmsGCOption = "-XX:+UseConcMarkSweepGC";
				String ddScale = "-Dsun.java2d.ddscale=true";
				String largeMaxHeap = "-Xmx128m";
				String translAccel = "-Dsun.java2d.translaccel=true";
				String ddForceVRAM = "-Dsun.java2d.ddforcevram=true";
				String noddraw = "-Dsun.java2d.noddraw=true";

				String commandString = System.getProperty("java.home")+fileSeparator+"bin"+fileSeparator+"java.exe"+" ";
				if (enableServerVM){
					commandString += serverVMOption+" ";
				}
				if (enableOpenGL){
					commandString += openGLOption+" ";
				}
				if (enableCMSGC){
					commandString += cmsGCOption+" ";
				}
				if (enableDDScale){
					commandString += ddScale+" ";
				}
				if (enableLargeMaxHeap){
					commandString += largeMaxHeap+" ";
				}
				if (enableTranslAccel){
					commandString += translAccel+" ";
				}
				if (enableDDForceVRAM){
					commandString += ddForceVRAM+" ";
				}
				if (enableNoddraw){
					commandString += noddraw+" ";
				}

				String fullClassName = Main.class.getCanonicalName();
				commandString += classPathOption+" "+fullClassName+" "+noOptions;

				System.out.println(commandString);

				System.out.println("about to launch new VM with options");

				Runtime.getRuntime().exec(commandString);
}

Basic question:
Can WebStart set (non-standard) Java2D options? (ie, options besides noddraw)
If not, is there a hack, similar to the code above?

this isn’t exactly a hack but some of the options can be set in your app instead of the java web start using something like

System.setProperty("Dsun.java2d.translaccel", "true");

however doesn’t work for all types of options but should be ok for most

Cheers kapta 8).

I thought that most of those kind of options had to be set at the outset, for example when you set the OGL pipeline it has to be done before any directdraw has happened.

It would be wise to put the System.setProperty stuff in the main method rather than say in the paint method before anything actually paints; you never know what might happen with initilisation and the like…

A static initializer block in the main class is the earliest you can run any of your applications code. I usually put code that sets flags like that there.

Thanks a lot for the help. By the way, I’m a little in awe at how you all know that you can set flags using System.setProperty(String, String)?

The API docs http://java.sun.com/j2se/1.5.0/docs/api/ for System drop only a very feint hint that you can do it (and its in the class description, not in the setProperty method). I can’t believe that I’ve been using the above hack for so long! :stuck_out_tongue: It really sucked because I had to wait for two VM’s to load! This is at least 100 times better :smiley:

Many thanks,
Keith

AFAIK the UI is loaded previous to the main-class static-block, as the webstart UI is already loaded.

Launching a new VM with the proper flags might be the only way.

I hope you’re wrong :). My guess is that WebStart doesn’t load the UI since the loading screen has a Windows look & feel and not Swing’s default Ocean. Perhaps its a native dialog? Loading look&feels takes too long anyway, I doubt that webstart would waste the time. Besides, how could JOGL apps that are combined with Swing use WebStart when they need to turn on J2D’s openGL pipeline?

Also Chet Haase prescribes it here: http://weblogs.java.net/blog/chet/archive/2004/09/index.html

You can play with the OpenGL implementation by passing in a command-line argument to tell us to enable it:

java -Dsun.java2d.opengl=true 

or you can set the same system property in your main() method:

System.setProperty("sun.java2d.opengl", "true");

As soon as I can get my stupid server mime.type fixed I’ll try the above with WebStart and report back for anyone interested.

Thanks,
Keith

You CAN set these properties in your jnlp file when your application is signed ().
This limitation is only for untrusted application.

Lilian :slight_smile:

Thanks Lilian :).

I think I’ll go with the System.setProperty(…) anyway so the plain old jar will work on its own.

As you want

(but remember System.setProperty() also requires signing as you’re touching secured properties, so you’ll have to sign your jar anyway.)

Lilian :slight_smile:

Off the top of my head … doesn’t webstart do some smart stuff with launching the app in fresh classloaders and fresh system resources (including graphics) ?

It seems like Riven was right. WebStart isn’t honouring the J2D System property options I’m setting from the main class’s static initialisation block. :frowning: What a bugger. That means I’ll have to set them from the jnlp file which sucks because then I’ll need to

enable one set of options when they’re not ideal or
have multiple copies of my game’s jnlp file posted on the website which have the different options

Can anybody think of a way to get around it? Even a way to start another VM would be OK. My way above doesn’t work with WebStart (or with a non-windows box).

Well I wouldn’t call it a bug, webstart simply loads AWT before your program starts, its the same as with applets.

lg Clemens

Hehe, you’re right, I didn’t mean it like that :). Bugger is colloquial in Australian. Its kind of like saying ‘what a bummer’ or ‘darn’. :wink:

In Mustang we added a number of additional system properties to the “secure” list:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6250769

This includes 2D-specific flags like:
sun.java2d.opengl
sun.java2d.d3d

Unfortunately, it appears that the developer’s guide wasn’t updated accordingly for Mustang to mention these new properties:
http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html

So I just filed a doc bug on Java Web Start so that they update that document properly (this bug should be visible tomorrow):
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6447014

As folks have discovered already in this thread, there’s really no way to call System.setProperty() or similar and have the OGL/D3D flags take effect from within a Web Start application, since it’s too late at that point. So the only way to make these flags have an effect is to pass them from the JNLP file, as is now allowed in Mustang.

Chris

Thanks for the help Chris.

I notice that the following Windows options aren’t in that ‘secure’ list:
sun.java2d.translaccel=true
sun.java2d.ddforcevram=true
sun.java2d.ddscale=true

2nd to the OGL option, these arguments provide the best J2D performance of all in Mustang (on my box).
Since d3d has less driver trouble than OGL, it would be great to put them on the safe list too. Just a suggestion that probably will only help us gaming folks, but worth a try :).
Keith

lol … I guess this comes from writing before thinking ^^
However Australia is great dreaming :slight_smile:

lg Clemens

Does anyone know how to relaunch the VM programmatically? ie start a new VM from a running WebStarted VM? I want to be able to relaunch my game with different J2D system properties.

If this can’t be done then I’ll have to have 3+ versions of my JNLP file: a default one, an openGL pipeline one & a fully-enabled directdraw version. That would be bad, so any help is appreciated!

Thanks,
Keith