1 /* org.sablevm.vm.BootstrapClassLoader 2 Copyright (C) 2002 Free Software Foundation 3 4 Modifications Copyright (C) 2004 by Etienne Gagnon. 5 Modifications Copyright (C) 2004 by David Belanger. 6 Modifications Copyright (C) 2004, 2005 by Grzegorz Prokopski. 7 8 This file is part of the SableVM class library. 9 10 The SableVM class library is free software; you can redistribute it 11 and/or modify it under the terms of the GNU General Public License as 12 published by the Free Software Foundation; either version 2, or (at 13 your option) any later version. 14 15 The SableVM class library is distributed in the hope that it will be 16 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with the SableVM class library; see the file COPYING. If not, 22 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 23 330, Boston, MA 02111-1307 USA. 24 25 Linking this library statically or dynamically with other modules is 26 making a combined work based on this library. Thus, the terms and 27 conditions of the GNU General Public License cover the whole 28 combination. 29 30 As a special exception, the copyright holders of this library give you 31 permission to link this library with independent modules to produce an 32 executable, regardless of the license terms of these independent 33 modules, and to copy and distribute the resulting executable under 34 terms of your choice, provided that you also meet, for each linked 35 independent module, the terms and conditions of the license of that 36 module. An independent module is a module which is not derived from 37 or based on this library. If you modify this library, you may extend 38 this exception to your version of the library, but you are not 39 obligated to do so. If you do not wish to do so, delete this 40 exception statement from your version. */ 41 42 package java.lang; 43 44 import java.io.*; 45 import java.util.*; 46 import java.lang.reflect.*; 47 48 /** 49 * @author Etienne M. Gagnon <etienne.gagnon@uqam,ca> 50 */ 51 class VirtualMachine 52 { 53 /* useful routines for debugging (they do not require the full 54 * java.io infrastructure). */ print(boolean b)55 public static native void print(boolean b); print(byte b)56 public static native void print(byte b); print(short s)57 public static native void print(short s); print(char c)58 public static native void print(char c); print(int i)59 public static native void print(int i); print(long l)60 public static native void print(long l); print(float f)61 public static native void print(float f); print(double d)62 public static native void print(double d); print(String s)63 public static native void print(String s); 64 println(boolean b)65 public static native void println(boolean b); println(byte b)66 public static native void println(byte b); println(short s)67 public static native void println(short s); println(char c)68 public static native void println(char c); println(int i)69 public static native void println(int i); println(long l)70 public static native void println(long l); println(float f)71 public static native void println(float f); println(double d)72 public static native void println(double d); println(String s)73 public static native void println(String s); 74 exceptionDescribe(Throwable e)75 private static void exceptionDescribe(Throwable e) 76 { 77 e.printStackTrace(); 78 } 79 exceptionDescription(Throwable e)80 private static String exceptionDescription(Throwable e) throws IOException 81 { 82 StringWriter sw = new StringWriter(); 83 PrintWriter pw = new PrintWriter(sw); 84 e.printStackTrace(pw); 85 pw.close(); 86 sw.close(); 87 return sw.toString(); 88 } 89 exceptionTruncatedDescription(Throwable e)90 private static String exceptionTruncatedDescription(Throwable e) 91 { 92 return e.toString(); 93 } 94 main(String[] args)95 private static void main(String[] args) 96 throws ClassNotFoundException 97 { 98 ClassLoader cl = ClassLoader.getSystemClassLoader(); 99 Class mainClass = cl.loadClass(args[0]); 100 101 // If you want to use the bootstrap class loader instead, replace 102 // the above two lines by the following one: 103 // Class mainClass = VMClassLoader.loadClass(args[0], false); 104 105 String[] newArgs = new String[args.length - 1]; 106 System.arraycopy(args, 1, newArgs, 0, args.length - 1); 107 108 invokeMain (mainClass, newArgs); 109 } 110 invokeMain(Class mainClass, String[] newArgs)111 private static native void invokeMain(Class mainClass, String[] newArgs); 112 createClass(ClassLoader cl, String name)113 private static Class createClass(ClassLoader cl, String name) 114 throws ClassNotFoundException 115 { 116 return cl.loadClass(name.replace('/','.')); 117 } 118 createArray(ClassLoader cl, String name)119 private static Class createArray(ClassLoader cl, String name) 120 throws ClassNotFoundException 121 { 122 return cl.createArray(name.replace('/','.'), false); 123 } 124 125 private static int numRootThreadsCreated; 126 createRootThread(byte[] vmData)127 private static Thread createRootThread(byte[] vmData) 128 { 129 Thread thread = new Thread("Main-" + ++numRootThreadsCreated, ThreadGroup.root); 130 thread.vmData = vmData; 131 132 return thread; 133 } 134 runThread()135 private static void runThread() 136 { 137 Thread.currentThread().callRun(); 138 } 139 getSystemClassLoader()140 private static byte[] getSystemClassLoader() 141 { 142 return ClassLoader.getSystemClassLoader().vmData; 143 } 144 } 145