001/*
002 *  This file is part of the Jikes RVM project (http://jikesrvm.org).
003 *
004 *  This file is licensed to You under the Eclipse Public License (EPL);
005 *  You may not use this file except in compliance with the License. You
006 *  may obtain a copy of the License at
007 *
008 *      http://www.opensource.org/licenses/eclipse-1.0.php
009 *
010 *  See the COPYRIGHT.txt file distributed with this work for information
011 *  regarding copyright ownership.
012 */
013package gnu.classpath;
014
015import java.util.Properties;
016
017import org.jikesrvm.VM;     // for VM.sysWrite()
018import org.jikesrvm.Configuration;
019import org.jikesrvm.classloader.RVMClassLoader;
020import org.jikesrvm.runtime.CommandLineArgs;
021import org.jikesrvm.classloader.BootstrapClassLoader;
022import org.jikesrvm.scheduler.Lock;
023
024/**
025 * Jikes RVM implementation of GNU Classpath's gnu.classpath.VMSystemProperties.
026 * <P>
027 * Library support interface of Jikes RVM.  See the Javadoc documentation for
028 * GNU Classpath's reference implementation of VMSystemProperties -- for
029 * copyright reasons, we cannot duplicate it here.
030 */
031
032public class VMSystemProperties {
033
034  public static void preInit(Properties p) {
035    p.put("java.version", "1.6.0"); /* This is a lie, of course -- we don't
036                                       really support all 1.6 features, such
037                                       as assertions.  However, it is a
038                                       necessary lie, since Eclipse 3.0
039                                       explicitly tests java.version and
040                                       insists upon at least 1.4.1 to run. */
041    p.put("java.vendor", "Jikes RVM Project");
042    p.put("java.vm.vendor", "Jikes RVM Project");
043    p.put("java.vendor.url", "http://jikesrvm.org");
044
045    p.put("java.specification.name", "Java Platform API Specification");
046    p.put("java.specification.vendor", "Sun Microsystems Inc.");
047    p.put("java.specification.version", "1.6");
048
049    p.put("java.vm.specification.name", "Java Virtual Machine Specification");
050    p.put("java.vm.specification.vendor", "Sun Microsystems Inc.");
051    p.put("java.vm.specification.version", "1.0");
052
053    /* 50.0 brings us through Java version 1.6. */
054    p.put("java.class.version", "50.0");
055
056    p.put("file.separator", "/");
057    p.put("path.separator", ":");
058    p.put("line.separator", "\n");
059
060    p.put("java.compiler", "JikesRVM");
061    p.put("java.vm.version", "1.6.0");
062    p.put("java.vm.name", "JikesRVM");
063    p.put("file.encoding", "8859_1");
064    p.put("java.io.tmpdir", "/tmp");
065    p.put("gnu.cpu.endian", Configuration.LittleEndian ? "little" : "big");
066
067    /* Properties for JMX; this lets the implementation know which
068     * features JikesRVM supports */
069    p.put("gnu.java.compiler.name", "JikesRVM");
070    if (VM.MeasureCompilation) {
071      p.put("gnu.java.lang.management.CompilationTimeSupport", "true");
072    }
073    if (Lock.STATS) {
074      p.put("gnu.java.lang.management.ThreadContentionSupport","true");
075    }
076
077    String s;
078    s = BootstrapClassLoader.getBootstrapRepositories();
079    p.put("java.boot.class.path", s);
080    /* sun.boot.class.path is not necessary, yes, but possibly useful; Steve
081     * Augart has seen at least one piece of code on the web that reads
082     * this. */
083    p.put("sun.boot.class.path", s);
084
085
086    /* user.timezone
087
088       I (Steve Augart) started a discussion about this on classpath@gnu.org
089       on 23 March 2003.  Summary: we define user.timezone specifically in
090       order to pass that information to GNU Classpath's implementation of
091       java.util.TimeZone, which initializes
092       later on in the boot process.  It does not seem to be required by the
093       spec, and it's the empty string in Blackdown 1.4.2.
094
095       We have to do this here, because otherwise it wouldn't be set until
096       CommandLineArgs.lateProcessCommandLineArguments().  That won't occur
097       until the VM is fully booted; too late for java.util.TimeZone, which
098       reads this value when it runs its initializer.
099    */
100    s = CommandLineArgs.getEnvironmentArg("user.timezone");
101    s = (s == null) ? "" : s;   // Maybe it's silly to set it to the empty
102                                // string.  Well, this should never succeed
103                                // anyway, since we're always called by
104                                // runrvm, which explicitly sets the value.
105    p.put("user.timezone", s);
106
107    /* java.library.path
108       Now the library path.  This is the path used for system
109       dynamically-loaded libraries, the things that end in ".so" on Linux. */
110    insertLibraryPath(p);
111
112    /* What should we do about java.ext.dirs?
113       XXX TODO
114
115       java.ext.dirs is allegedly mandatory, according to the API docs shipped
116       with the Sun 1.4.2 JDK.
117
118       Ridiculous, since we don't search it for anything, and since if the
119       user were to set it it wouldn't do anything anyway.   We keep all of
120       the extensions stored with the other bits of the JDK.   So, this would
121       really need to be prepended to the list of VM classes, wouldn't it?  Or
122       appended, perhaps? */
123    s = CommandLineArgs.getEnvironmentArg("java.ext.dirs");
124    if (s == null) {
125      s = "";
126    } else {
127      VM.sysWrite("Jikes RVM: Warning: You have explicitly set java.ext.dirs; that will not do anything under Jikes RVM");
128    }
129    p.put("java.ext.dirs", s);
130
131
132    /* We also set java.class.path in setApplicationRepositories().
133     *  We'll treat setting the java.class.path property as essentially
134     * equivalent to using the -classpath argument. */
135    s = CommandLineArgs.getEnvironmentArg("java.class.path");
136    if (s != null) {
137      p.put("java.class.path", s);
138      RVMClassLoader.stashApplicationRepositories(s);
139    } else {
140      p.put("java.class.path", RVMClassLoader.getApplicationRepositories());
141    }
142
143    if (VM.PortableNativeSync) {
144      /* Enable portable native sync to support M-to-N threading with gtk peers */
145      p.put("gnu.classpath.awt.gtk.portable.native.sync", "true");
146    }
147
148    /* Now the rest of the special ones that we set on the command line.   Do
149     * this just in case later revisions of GNU Classpath start to require
150     * some of them in the boot process; otherwise, we could wait for them to
151     * be set in CommandLineArgs.lateProcessCommandLineArguments() */
152    final String[] clProps = new String[] {"os.name", "os.arch", "os.version", "user.name", "user.home", "user.dir", "gnu.classpath.vm.shortname", "gnu.classpath.home.url", "java.home"};
153
154    for (final String prop : clProps) {
155      s = CommandLineArgs.getEnvironmentArg(prop);
156      if (s != null) {
157        p.put(prop, s);
158      }
159    }
160  }
161
162  /** Set java.library.path.<p>
163   *
164   * I wish I knew where to check in the source code to confirm that this
165   * is, in fact, the process we actually follow.  I do not understand this
166   * code.  I do not understand why we are adding something to
167   * java.library.path.  --Steve Augart, 3/23/2004 XXX
168   *
169   * @param p the properties to modify
170   */
171  private static void insertLibraryPath(Properties p) {
172    String jlp = CommandLineArgs.getEnvironmentArg("java.library.path");
173    String snp = CommandLineArgs.getEnvironmentArg("java.home");
174    if (jlp == null) jlp = ".";
175    p.put("java.library.path", snp + p.get("path.separator") + jlp);
176  }
177
178
179  /**
180   * Override the default SystemProperties code; insert the command-line
181   * arguments.
182   * <p>
183   * The following are set by the "runrvm" script before we go into the C
184   * bootloader, by passing them as command-line args with the -D flag:
185   * <p>
186   * os.name, os.arch, os.version
187   * user.name, user.home, user.dir
188   * gnu.classpath.vm.shortname, gnu.classpath.home.url,
189   * java.home,
190   * <p>
191   * We can look at them here via CommandLineArgs.getEnvironmentArg().
192   * <p>
193   * They will be automatically set for us by
194   * CommandLineArgs.lateProcessCommandLineArguments() if we do not handle
195   * them here.  That won't occur until the VM is fully booted.  That's too
196   * late for some classes, such as java.util.TimeZone, which will already be
197   * initialized.
198   * <p>
199   * In any case, this function isn't used in Jikes RVM.  Our boot sequence
200   * is already handling this OK.
201   *
202   * @param properties the properties to modify
203   */
204  public static void postInit(Properties properties) {
205  }
206}