use of org.jikesrvm.scheduler.MainThread in project JikesRVM by JikesRVM.
the class VM method finishBooting.
/**
* Complete the task of booting Jikes RVM.
* Done in a secondary method mainly because this code
* doesn't have to be uninterruptible and this is the cleanest
* way to make that distinction.
*/
@Interruptible
private static void finishBooting() {
// get pthread_id from OS and store into vm_processor field
//
RVMThread.getCurrentThread().pthread_id = sysCall.sysGetThreadId();
RVMThread.getCurrentThread().priority_handle = sysCall.sysGetThreadPriorityHandle();
RVMThread.availableProcessors = SysCall.sysCall.sysNumProcessors();
// Set up buffer locks used by Thread for logging and status dumping.
// This can happen at any point before we start running
// multi-threaded.
Services.boot();
//
if (verboseBoot >= 1) {
VM.sysWriteln("Setting up memory manager: bootrecord = ", Magic.objectAsAddress(BootRecord.the_boot_record));
}
MemoryManager.boot(BootRecord.the_boot_record);
//
if (verboseBoot >= 1)
VM.sysWriteln("Initializing baseline compiler options to defaults");
BaselineCompiler.initOptions();
//
if (verboseBoot >= 1)
VM.sysWriteln("Fetching command-line arguments");
CommandLineArgs.fetchCommandLineArguments();
//
if (verboseBoot >= 1)
VM.sysWriteln("Early stage processing of command line");
CommandLineArgs.earlyProcessCommandLineArguments();
// Early initialization of TuningFork tracing engine.
TraceEngine.engine.earlyStageBooting();
//
if (verboseBoot >= 1)
VM.sysWriteln("Collector processing rest of boot options");
MemoryManager.postBoot();
// Initialize class loader.
//
String bootstrapClasses = CommandLineArgs.getBootstrapClasses();
if (verboseBoot >= 1)
VM.sysWriteln("Initializing bootstrap class loader: ", bootstrapClasses);
Callbacks.addClassLoadedMonitor(JMXSupport.CLASS_LOADING_JMX_SUPPORT);
// Wipe out cached application class loader
RVMClassLoader.boot();
BootstrapClassLoader.boot(bootstrapClasses);
//
if (verboseBoot >= 1)
VM.sysWriteln("Running various class initializers");
if (VM.BuildForGnuClasspath) {
// Need for ThreadLocal
runClassInitializer("java.util.WeakHashMap");
}
runClassInitializer("org.jikesrvm.classloader.Atom$InternedStrings");
if (VM.BuildForGnuClasspath) {
runClassInitializer("gnu.classpath.SystemProperties");
runClassInitializer("java.lang.Throwable$StaticData");
}
runClassInitializer("java.lang.Runtime");
runClassInitializer("java.lang.System");
runClassInitializer("sun.misc.Unsafe");
runClassInitializer("java.lang.Character");
runClassInitializer("org.jikesrvm.classloader.TypeReferenceVector");
runClassInitializer("org.jikesrvm.classloader.MethodVector");
runClassInitializer("org.jikesrvm.classloader.FieldVector");
// java.security.JikesRVMSupport.turnOffChecks();
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.lang.ThreadGroup");
}
/* We can safely allocate a java.lang.Thread now. The boot
thread (running right now, as a Thread) has to become a full-fledged
Thread, since we're about to encounter a security check:
EncodingManager checks a system property,
which means that the permissions checks have to be working,
which means that VMAccessController will be invoked,
which means that ThreadLocal.get() will be called,
which calls Thread.getCurrentThread().
So the boot Thread needs to be associated with a real Thread for
Thread.getCurrentThread() to return. */
VM.safeToAllocateJavaThread = true;
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.lang.ThreadLocal");
runClassInitializer("java.lang.ThreadLocalMap");
}
// Possibly fix VMAccessController's contexts and inGetContext fields
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.security.VMAccessController");
}
if (VM.BuildForHarmony) {
runClassInitializer("java.security.AccessController");
}
if (verboseBoot >= 1)
VM.sysWriteln("Booting Lock");
Lock.boot();
//
if (verboseBoot >= 1)
VM.sysWriteln("Booting scheduler");
RVMThread.boot();
DynamicLibrary.boot();
if (verboseBoot >= 1)
VM.sysWriteln("Enabling GC");
MemoryManager.enableCollection();
if (verboseBoot >= 1)
VM.sysWriteln("Setting up boot thread");
RVMThread.getCurrentThread().setupBootJavaThread();
// Create JNI Environment for boot thread.
// After this point the boot thread can invoke native methods.
org.jikesrvm.jni.JNIEnvironment.boot();
if (verboseBoot >= 1)
VM.sysWriteln("Initializing JNI for boot thread");
RVMThread.getCurrentThread().initializeJNIEnv();
if (verboseBoot >= 1)
VM.sysWriteln("JNI initialized for boot thread");
if (VM.BuildForHarmony) {
System.loadLibrary("hyluni");
System.loadLibrary("hythr");
System.loadLibrary("hyniochar");
}
// needed for when we initialize the
runClassInitializer("java.io.File");
// system/application class loader.
runClassInitializer("java.lang.String");
if (VM.BuildForGnuClasspath) {
runClassInitializer("gnu.java.security.provider.DefaultPolicy");
}
// needed for URLClassLoader
runClassInitializer("java.net.URL");
/* Needed for ApplicationClassLoader, which in turn is needed by
VMClassLoader.getSystemClassLoader() */
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.net.URLClassLoader");
}
/* Used if we start up Jikes RVM with the -jar argument; that argument
* means that we need a working -jar before we can return an
* Application Class Loader. */
runClassInitializer("java.net.URLConnection");
if (VM.BuildForGnuClasspath) {
runClassInitializer("gnu.java.net.protocol.jar.Connection$JarFileCache");
runClassInitializer("java.lang.ClassLoader$StaticData");
}
runClassInitializer("java.lang.Class$StaticData");
runClassInitializer("java.nio.charset.Charset");
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.nio.charset.CharsetEncoder");
}
runClassInitializer("java.nio.charset.CoderResult");
if (VM.BuildForHarmony) {
runClassInitializer("org.apache.harmony.niochar.CharsetProviderImpl");
}
// Uses System.getProperty
runClassInitializer("java.io.PrintWriter");
System.setProperty("line.separator", "\n");
// Uses System.getProperty
runClassInitializer("java.io.PrintStream");
runClassInitializer("java.util.Locale");
runClassInitializer("java.util.ResourceBundle");
runClassInitializer("java.util.zip.CRC32");
if (VM.BuildForHarmony) {
System.loadLibrary("hyarchive");
}
runClassInitializer("java.util.zip.Inflater");
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.util.zip.DeflaterHuffman");
runClassInitializer("java.util.zip.InflaterDynHeader");
runClassInitializer("java.util.zip.InflaterHuffmanTree");
}
// Run class initializers that require JNI
if (verboseBoot >= 1)
VM.sysWriteln("Running late class initializers");
if (VM.BuildForGnuClasspath) {
System.loadLibrary("javaio");
}
runClassInitializer("java.lang.Math");
runClassInitializer("java.util.TreeMap");
if (VM.BuildForGnuClasspath) {
runClassInitializer("gnu.java.nio.VMChannel");
runClassInitializer("gnu.java.nio.FileChannelImpl");
}
runClassInitializer("java.io.FileDescriptor");
runClassInitializer("java.io.FilePermission");
runClassInitializer("java.util.jar.JarFile");
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.util.zip.ZipFile$PartialInputStream");
}
runClassInitializer("java.util.zip.ZipFile");
if (VM.BuildForHarmony) {
runClassInitializer("java.util.Hashtable");
runClassInitializer("java.util.jar.Manifest");
runClassInitializer("java.util.jar.Attributes$Name");
runClassInitializer("java.util.BitSet");
runClassInitializer("java.util.regex.Matcher");
runClassInitializer("java.util.regex.Pattern");
runClassInitializer("org.apache.harmony.luni.internal.net.www.protocol.jar.JarURLConnection");
runClassInitializer("org.apache.harmony.luni.platform.OSMemory");
runClassInitializer("org.apache.harmony.luni.platform.Platform");
runClassInitializer("org.apache.harmony.luni.platform.AbstractMemorySpy");
runClassInitializer("org.apache.harmony.luni.platform.PlatformAddress");
runClassInitializer("org.apache.harmony.nio.internal.FileChannelImpl");
runClassInitializer("com.ibm.icu.util.ULocale");
runClassInitializer("java.io.ObjectStreamClass");
runClassInitializer("java.io.ObjectStreamClass$OSCThreadLocalCache");
runClassInitializer("java.io.ObjectInputStream");
runClassInitializer("java.security.MessageDigest");
}
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.lang.VMDouble");
}
runClassInitializer("java.util.PropertyPermission");
runClassInitializer("org.jikesrvm.classloader.RVMAnnotation");
runClassInitializer("java.lang.annotation.RetentionPolicy");
runClassInitializer("java.lang.annotation.ElementType");
runClassInitializer("java.lang.Thread$State");
if (VM.BuildForGnuClasspath) {
runClassInitializer("gnu.java.nio.charset.EncodingHelper");
runClassInitializer("java.lang.VMClassLoader");
}
if (verboseBoot >= 1)
VM.sysWriteln("initializing standard streams");
// Initialize java.lang.System.out, java.lang.System.err, java.lang.System.in
FileSystem.initializeStandardStreams();
// /////////////////////////////////////////////////////////////
if (verboseBoot >= 1)
VM.sysWriteln("VM is now fully booted");
// Inform interested subsystems that VM is fully booted.
VM.fullyBooted = true;
MemoryManager.fullyBootedVM();
org.jikesrvm.mm.mminterface.JMXSupport.fullyBootedVM();
BaselineCompiler.fullyBootedVM();
TraceEngine.engine.fullyBootedVM();
runClassInitializer("java.util.logging.Level");
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.lang.reflect.Proxy");
runClassInitializer("java.lang.reflect.Proxy$ProxySignature");
}
runClassInitializer("java.util.logging.Logger");
if (VM.BuildForHarmony) {
Entrypoints.luni1.setObjectValueUnchecked(null, null);
Entrypoints.luni2.setObjectValueUnchecked(null, null);
Entrypoints.luni3.setObjectValueUnchecked(null, null);
Entrypoints.luni4.setObjectValueUnchecked(null, null);
Entrypoints.luni5.setObjectValueUnchecked(null, null);
Entrypoints.luni6.setObjectValueUnchecked(null, null);
// runClassInitializer("java.lang.String$ConsolePrintStream");
runClassInitializer("org.apache.harmony.luni.util.Msg");
runClassInitializer("org.apache.harmony.archive.internal.nls.Messages");
runClassInitializer("org.apache.harmony.luni.internal.nls.Messages");
runClassInitializer("org.apache.harmony.nio.internal.nls.Messages");
runClassInitializer("org.apache.harmony.niochar.internal.nls.Messages");
runClassInitializer("java.util.logging.LogManager");
}
//
if (verboseBoot >= 1)
VM.sysWriteln("Initializing runtime compiler");
RuntimeCompiler.boot();
// Process remainder of the VM's command line arguments.
if (verboseBoot >= 1)
VM.sysWriteln("Late stage processing of command line");
String[] applicationArguments = CommandLineArgs.lateProcessCommandLineArguments();
if (VM.verboseClassLoading || verboseBoot >= 1)
VM.sysWriteln("[VM booted]");
if (VM.BuildForAdaptiveSystem) {
if (verboseBoot >= 1)
VM.sysWriteln("Initializing adaptive system");
Controller.boot();
}
// The first argument must be a class name.
if (verboseBoot >= 1)
VM.sysWriteln("Extracting name of class to execute");
if (applicationArguments.length == 0) {
pleaseSpecifyAClass();
}
if (applicationArguments.length > 0 && !TypeDescriptorParsing.isJavaClassName(applicationArguments[0])) {
VM.sysWrite("vm: \"");
VM.sysWrite(applicationArguments[0]);
VM.sysWriteln("\" is not a legal Java class name.");
pleaseSpecifyAClass();
}
if (applicationArguments.length > 0 && applicationArguments[0].startsWith("-X")) {
VM.sysWrite("vm: \"");
VM.sysWrite(applicationArguments[0]);
VM.sysWriteln("\" is not a recognized Jikes RVM command line argument.");
VM.sysExit(EXIT_STATUS_BOGUS_COMMAND_LINE_ARG);
}
if (verboseBoot >= 1)
VM.sysWriteln("Initializing Application Class Loader");
RVMClassLoader.getApplicationClassLoader();
RVMClassLoader.declareApplicationClassLoaderIsReady();
if (verboseBoot >= 1) {
VM.sysWriteln("Turning back on security checks. Letting people see the ApplicationClassLoader.");
}
if (VM.BuildForGnuClasspath) {
runClassInitializer("java.lang.ClassLoader$StaticData");
}
if (VM.BuildForAdaptiveSystem) {
CompilerAdvice.postBoot();
}
// enable alignment checking
if (VM.AlignmentChecking) {
SysCall.sysCall.sysEnableAlignmentChecking();
}
Time.boot();
// Set up properties for our custom JUnit test runner.
Configuration.setupPropertiesForUnitTesting();
// Schedule "main" thread for execution.
if (verboseBoot >= 2)
VM.sysWriteln("Creating main thread");
// Create main thread.
if (verboseBoot >= 1)
VM.sysWriteln("Constructing mainThread");
mainThread = new MainThread(applicationArguments);
// Schedule "main" thread for execution.
if (verboseBoot >= 1)
VM.sysWriteln("Starting main thread");
mainThread.start();
//
if (VM.TraceThreads)
RVMThread.trace("VM.boot", "completed - terminating");
if (verboseBoot >= 2) {
VM.sysWriteln("Boot sequence completed; finishing boot thread");
}
RVMThread.getCurrentThread().terminate();
if (VM.VerifyAssertions)
VM._assert(VM.NOT_REACHED);
}
Aggregations