Inheritance: java.lang.Object, Runnable
Example #1
0
 public NetworkManager(Socket socket, string s, NetHandler nethandler)
 {
     sendQueueLock = new object();
     m_isRunning = true;
     readPackets = Collections.synchronizedList(new ArrayList());
     dataPackets = Collections.synchronizedList(new ArrayList());
     chunkDataPackets = Collections.synchronizedList(new ArrayList());
     m_isServerTerminating = false;
     isTerminating = false;
     terminationReason = "";
     timeSinceLastRead = 0;
     sendQueueByteLength = 0;
     chunkDataSendCounter = 0;
     field_20175_w = 50;
     networkSocket = socket;
     remoteSocketAddress = socket.getRemoteSocketAddress();
     netHandler = nethandler;
     socket.setTrafficClass(24);
     socketInputStream = new DataInputStream(socket.getInputStream());
     socketOutputStream = new DataOutputStream(socket.getOutputStream());
     readThread = new NetworkReaderThread(this, (new StringBuilder()).append(s).append(" read thread").toString());
     writeThread = new NetworkWriterThread(this,
                                           (new StringBuilder()).append(s).append(" write thread").toString());
     readThread.start();
     writeThread.start();
 }
 /// <summary>
 /// Create a thread.
 /// </summary>
 /// <seealso cref= ThreadFactory#newThread(java.lang.Runnable) </seealso>
 public virtual java.lang.Thread newThread(Runnable r)
 {
     java.lang.Thread thread = new java.lang.Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
     thread.setDaemon(isDaemon);
     if (thread.getPriority() != Thread.NORM_PRIORITY)
     {
         thread.setPriority(Thread.NORM_PRIORITY);
     }
     return(thread);
 }
Example #3
0
 public NetworkListenThread(MinecraftServer minecraftserver, InetAddress inetaddress, int i)
 {
     field_973_b = false;
     field_977_f = 0;
     pendingConnections = new ArrayList();
     playerList = new ArrayList();
     mcServer = minecraftserver;
     serverSocket = new ServerSocket(i, 0, inetaddress);
     serverSocket.setPerformancePreferences(0, 2, 1);
     field_973_b = true;
     networkAcceptThread = new NetworkAcceptThread(this, "Listen thread", minecraftserver);
     networkAcceptThread.start();
 }
Example #4
0
    public static object getThreads()
    {
#if FIRST_PASS
        return(null);
#else
        return(java.security.AccessController.doPrivileged(ikvm.runtime.Delegates.toPrivilegedAction(delegate
        {
            java.lang.ThreadGroup root = (java.lang.ThreadGroup)mainThreadGroup;
            for (; ;)
            {
                java.lang.Thread[] threads = new java.lang.Thread[root.activeCount()];
                if (root.enumerate(threads) == threads.Length)
                {
                    return threads;
                }
            }
        })));
#endif
    }
Example #5
0
 private static void DumpAllJavaThreads()
 {
     Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
     java.util.Map traces = java.lang.Thread.getAllStackTraces();
     Console.WriteLine("Full thread dump IKVM.NET {0} ({1} bit):", JVM.SafeGetAssemblyVersion(Assembly.GetExecutingAssembly()), IntPtr.Size * 8);
     java.util.Iterator entries = traces.entrySet().iterator();
     while (entries.hasNext())
     {
         java.util.Map.Entry entry  = (java.util.Map.Entry)entries.next();
         java.lang.Thread    thread = (java.lang.Thread)entry.getKey();
         Console.WriteLine("\n\"{0}\"{1} prio={2} tid=0x{3:X8}", thread.getName(), thread.isDaemon() ? " daemon" : "", thread.getPriority(), thread.getId());
         Console.WriteLine("   java.lang.Thread.State: " + thread.getState());
         java.lang.StackTraceElement[] trace = (java.lang.StackTraceElement[])entry.getValue();
         for (int i = 0; i < trace.Length; i++)
         {
             Console.WriteLine("\tat {0}", trace[i]);
         }
     }
     Console.WriteLine();
 }
Example #6
0
 // Method Summary
 /// <summary>
 /// Registers a new virtual-machine shutdown hook.
 /// </summary>
 public void addShutdownHook(Thread hook)
 {
     return;
 }
Example #7
0
 /// <summary>
 /// De-registers a previously-registered virtual-machine shutdown hook.
 /// </summary>
 public bool removeShutdownHook(Thread hook)
 {
     return default(bool);
 }
Example #8
0
    static int Main(string[] args)
    {
        Tracer.EnableTraceConsoleListener();
        Tracer.EnableTraceForDebug();
        System.Collections.Hashtable props = new System.Collections.Hashtable();
        string classpath = Environment.GetEnvironmentVariable("CLASSPATH");

        if (classpath == null || classpath == "")
        {
            classpath = ".";
        }
        props["java.class.path"] = classpath;
        bool   jar           = false;
        bool   saveAssembly  = false;
        bool   saveAssemblyX = false;
        bool   waitOnExit    = false;
        bool   showVersion   = false;
        string mainClass     = null;
        int    vmargsIndex   = -1;
        bool   debug         = false;
        String debugArg      = null;
        bool   noglobbing    = false;

        for (int i = 0; i < args.Length; i++)
        {
            String arg = args[i];
            if (arg[0] == '-')
            {
                if (arg == "-help" || arg == "-?")
                {
                    PrintHelp();
                    return(1);
                }
                else if (arg == "-X")
                {
                    PrintXHelp();
                    return(1);
                }
                else if (arg == "-Xsave")
                {
                    saveAssembly = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (arg == "-XXsave")
                {
                    saveAssemblyX = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (arg == "-Xtime")
                {
                    new Timer();
                }
                else if (arg == "-Xwait")
                {
                    waitOnExit = true;
                }
                else if (arg == "-Xbreak")
                {
                    System.Diagnostics.Debugger.Break();
                }
                else if (arg == "-Xnoclassgc")
                {
                    IKVM.Internal.Starter.ClassUnloading = false;
                }
                else if (arg == "-Xverify")
                {
                    IKVM.Internal.Starter.RelaxedVerification = false;
                }
                else if (arg == "-jar")
                {
                    jar = true;
                }
                else if (arg == "-version")
                {
                    Console.WriteLine(Startup.getVersionAndCopyrightInfo());
                    Console.WriteLine();
                    Console.WriteLine("CLR version: {0} ({1} bit)", Environment.Version, IntPtr.Size * 8);
                    System.Type type = System.Type.GetType("Mono.Runtime");
                    if (type != null)
                    {
                        Console.WriteLine("Mono version: {0}", type.InvokeMember("GetDisplayName", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[0]));
                    }
                    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        Console.WriteLine("{0}: {1}", asm.GetName().Name, asm.GetName().Version);
                    }
                    string ver = java.lang.System.getProperty("openjdk.version");
                    if (ver != null)
                    {
                        Console.WriteLine("OpenJDK version: {0}", ver);
                    }
                    return(0);
                }
                else if (arg == "-showversion")
                {
                    showVersion = true;
                }
                else if (arg.StartsWith("-D"))
                {
                    arg = arg.Substring(2);
                    string[] keyvalue = arg.Split('=');
                    string   value;
                    if (keyvalue.Length == 2)                    // -Dabc=x
                    {
                        value = keyvalue[1];
                    }
                    else if (keyvalue.Length == 1) // -Dabc
                    {
                        value = "";
                    }
                    else // -Dabc=x=y
                    {
                        value = arg.Substring(keyvalue[0].Length + 1);
                    }
                    props[keyvalue[0]] = value;
                }
                else if (arg == "-ea" || arg == "-enableassertions")
                {
                    IKVM.Runtime.Assertions.EnableAssertions();
                }
                else if (arg == "-da" || arg == "-disableassertions")
                {
                    IKVM.Runtime.Assertions.DisableAssertions();
                }
                else if (arg == "-esa" || arg == "-enablesystemassertions")
                {
                    IKVM.Runtime.Assertions.EnableSystemAssertions();
                }
                else if (arg == "-dsa" || arg == "-disablesystemassertions")
                {
                    IKVM.Runtime.Assertions.DisableSystemAssertions();
                }
                else if (arg.StartsWith("-ea:") || arg.StartsWith("-enableassertions:"))
                {
                    IKVM.Runtime.Assertions.EnableAssertions(arg.Substring(arg.IndexOf(':') + 1));
                }
                else if (arg.StartsWith("-da:") || arg.StartsWith("-disableassertions:"))
                {
                    IKVM.Runtime.Assertions.DisableAssertions(arg.Substring(arg.IndexOf(':') + 1));
                }
                else if (arg == "-cp" || arg == "-classpath")
                {
                    props["java.class.path"] = args[++i];
                }
                else if (arg.StartsWith("-Xtrace:"))
                {
                    Tracer.SetTraceLevel(arg.Substring(8));
                }
                else if (arg.StartsWith("-Xmethodtrace:"))
                {
                    Tracer.HandleMethodTrace(arg.Substring(14));
                }
                else if (arg == "-Xdebug")
                {
                    debug = true;
                }
                else if (arg == "-Xnoagent")
                {
                    //ignore it, disable support for oldjdb
                }
                else if (arg.StartsWith("-Xrunjdwp") || arg.StartsWith("-agentlib:jdwp"))
                {
                    debugArg = arg;
                    debug    = true;
                }
                else if (arg.StartsWith("-Xreference:"))
                {
                    Startup.addBootClassPathAssembly(Assembly.LoadFrom(arg.Substring(12)));
                }
                else if (arg == "-Xnoglobbing")
                {
                    noglobbing = true;
                }
                else if (arg == "-XX:+AllowNonVirtualCalls")
                {
                    IKVM.Internal.Starter.AllowNonVirtualCalls = true;
                }
                else if (arg.StartsWith("-Xms") ||
                         arg.StartsWith("-Xmx") ||
                         arg.StartsWith("-Xss") ||
                         arg == "-Xmixed" ||
                         arg == "-Xint" ||
                         arg == "-Xincgc" ||
                         arg == "-Xbatch" ||
                         arg == "-Xfuture" ||
                         arg == "-Xrs" ||
                         arg == "-Xcheck:jni" ||
                         arg == "-Xshare:off" ||
                         arg == "-Xshare:auto" ||
                         arg == "-Xshare:on"
                         )
                {
                    Console.Error.WriteLine("Unsupported option ignored: {0}", arg);
                }
                else
                {
                    Console.Error.WriteLine("{0}: illegal argument", arg);
                    break;
                }
            }
            else
            {
                mainClass   = arg;
                vmargsIndex = i + 1;
                break;
            }
        }
        if (mainClass == null || showVersion)
        {
            Console.Error.WriteLine(Startup.getVersionAndCopyrightInfo());
            Console.Error.WriteLine();
        }
        if (mainClass == null)
        {
            PrintHelp();
            return(1);
        }
        try
        {
            if (debug)
            {
                // Starting the debugger
                Assembly asm       = Assembly.GetExecutingAssembly();
                String   arguments = debugArg + " -pid:" + System.Diagnostics.Process.GetCurrentProcess().Id;
                String   program   = new FileInfo(asm.Location).DirectoryName + "\\debugger.exe";
                try
                {
                    ProcessStartInfo info = new ProcessStartInfo(program, arguments);
                    info.UseShellExecute = false;
                    Process debugger = new Process();
                    debugger.StartInfo = info;
                    debugger.Start();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(program + " " + arguments);
                    throw ex;
                }
            }
            if (jar)
            {
                props["java.class.path"] = mainClass;
            }
            // like the JDK we don't quote the args (even if they contain spaces)
            props["sun.java.command"]  = String.Join(" ", args, vmargsIndex - 1, args.Length - (vmargsIndex - 1));
            props["sun.java.launcher"] = "SUN_STANDARD";
            Startup.setProperties(props);
            Startup.enterMainThread();
            string[] vmargs;
            if (noglobbing)
            {
                vmargs = new string[args.Length - vmargsIndex];
                System.Array.Copy(args, vmargsIndex, vmargs, 0, vmargs.Length);
            }
            else
            {
                // Startup.glob() uses Java code, so we need to do this after we've initialized
                vmargs = Startup.glob(args, vmargsIndex);
            }
            try
            {
                java.lang.Class clazz = sun.launcher.LauncherHelper.checkAndLoadMain(true, jar ? 2 : 1, mainClass);
                // we don't need to do any checking on the main method, as that was already done by checkAndLoadMain
                Method method = clazz.getMethod("main", typeof(string[]));
                // if clazz isn't public, we can still call main
                method.setAccessible(true);
                if (saveAssembly)
                {
                    java.lang.Runtime.getRuntime().addShutdownHook(new SaveAssemblyShutdownHook(clazz));
                }
                if (waitOnExit)
                {
                    java.lang.Runtime.getRuntime().addShutdownHook(new WaitShutdownHook());
                }
                try
                {
                    method.invoke(null, new object[] { vmargs });
                    return(0);
                }
                catch (InvocationTargetException x)
                {
                    throw x.getCause();
                }
            }
            finally
            {
                if (saveAssemblyX)
                {
                    IKVM.Internal.Starter.SaveDebugImage();
                }
            }
        }
        catch (System.Exception x)
        {
            java.lang.Thread thread = java.lang.Thread.currentThread();
            thread.getThreadGroup().uncaughtException(thread, ikvm.runtime.Util.mapException(x));
        }
        finally
        {
            Startup.exitMainThread();
        }
        return(1);
    }
Example #9
0
public static global::System.Object currentThread(){
//XMLVM_BEGIN_WRAPPER[java.lang.Thread: java.lang.Thread currentThread()]
    // special case for native threads
    
    /*if (currentThreadInstance == null)
    {
        currentThreadInstance = new Thread();
        currentThreadInstance.@this(global::com.codename1.impl.SilverlightImplementation.toJava("native thread"));
    }
    return currentThreadInstance;*/
    if (!threadMap.ContainsKey(global::System.Threading.Thread.CurrentThread))
    {
        Thread t = new Thread();
        threadMap.Add(global::System.Threading.Thread.CurrentThread, t);
        return t;
    }
    return threadMap[global::System.Threading.Thread.CurrentThread];
//XMLVM_END_WRAPPER[java.lang.Thread: java.lang.Thread currentThread()]
}
Example #10
0
 public static object getThreads()
 {
     #if FIRST_PASS
     return null;
     #else
     return java.security.AccessController.doPrivileged(ikvm.runtime.Delegates.toPrivilegedAction(delegate
     {
         java.lang.ThreadGroup root = (java.lang.ThreadGroup)mainThreadGroup;
         for (; ; )
         {
             java.lang.Thread[] threads = new java.lang.Thread[root.activeCount()];
             if (root.enumerate(threads) == threads.Length)
             {
                 return threads;
             }
         }
     }));
     #endif
 }
Example #11
0
    public static void getThreadInfo1(long[] ids, int maxDepth, object result)
    {
#if !FIRST_PASS
        System.Reflection.ConstructorInfo[] constructors = typeof(java.lang.management.ThreadInfo).GetConstructors(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        foreach (System.Reflection.ConstructorInfo constructor in constructors)
        {
            if (constructor.GetParameters().Length == 9)
            {
                java.lang.Thread[] threads = (java.lang.Thread[])getThreads();
                java.lang.management.ThreadInfo[] threadInfos = (java.lang.management.ThreadInfo[])result;
                for (int i = 0; i < ids.Length; i++)
                {
                    long id = ids[i];
                    for (int t = 0; t < threads.Length; t++)
                    {
                        if (threads[t].getId() == id)
                        {
                            java.lang.Thread thread = threads[t];

                            int state;
                            // invers to sun.misc.VM.toThreadState
                            switch (thread.getState().ordinal())
                            {
                            case (int)java.lang.Thread.State.__Enum.RUNNABLE:
                                state = JVMTI_THREAD_STATE_RUNNABLE;
                                break;

                            case (int)java.lang.Thread.State.__Enum.BLOCKED:
                                state = JVMTI_THREAD_STATE_BLOCKED_ON_MONITOR_ENTER;
                                break;

                            case (int)java.lang.Thread.State.__Enum.WAITING:
                                state = JVMTI_THREAD_STATE_WAITING_INDEFINITELY;
                                break;

                            case (int)java.lang.Thread.State.__Enum.TIMED_WAITING:
                                state = JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT;
                                break;

                            case (int)java.lang.Thread.State.__Enum.TERMINATED:
                                state = JVMTI_THREAD_STATE_TERMINATED;
                                break;

                            case (int)java.lang.Thread.State.__Enum.NEW:
                                state = JVMTI_THREAD_STATE_ALIVE;
                                break;

                            default:
                                state = 0;
                                break;
                            }
                            //TODO set in state JMM_THREAD_STATE_FLAG_SUSPENDED if the thread is suspended

                            java.lang.StackTraceElement[] stacktrace = thread.getStackTrace();
                            if (maxDepth >= 0 && maxDepth < stacktrace.Length)
                            {
                                java.lang.StackTraceElement[] temp = new java.lang.StackTraceElement[maxDepth];
                                System.Array.Copy(stacktrace, temp, temp.Length);
                                stacktrace = temp;
                            }

                            object[] parameters = new object[9];
                            parameters[0] = thread;                     // thread
                            parameters[1] = state;                      // state
                                                                        // lockObj
                                                                        // lockOwner
                            parameters[4]  = 0;                         // blockedCount
                            parameters[5]  = 0;                         // blockedTime
                            parameters[6]  = -1;                        // waitedCount
                            parameters[7]  = 0;                         // waitedTime
                            parameters[8]  = stacktrace;                // stackTrace
                            threadInfos[i] = (java.lang.management.ThreadInfo)constructor.Invoke(parameters);
                            break;
                        }
                    }
                }
                return;
            }
        }
        throw new java.lang.InternalError("Constructor for java.lang.management.ThreadInfo not find.");
#endif
    }
 /// <summary>
 /// Copies into the specified array every active thread in this  thread group.
 /// </summary>
 public int enumerate(Thread[] list, bool recurse)
 {
     return default(int);
 }
 /// <summary>
 /// Copies into the specified array every active thread in this  thread group and its subgroups.
 /// </summary>
 public int enumerate(Thread[] list)
 {
     return default(int);
 }
 /// <summary>
 /// Called by the Java Virtual Machine when a thread in this  thread group stops because of an uncaught exception.
 /// </summary>
 public void uncaughtException(Thread t, Throwable e)
 {
 }
Example #15
0
        public static int StartMain(string[] args)
        {
            Tracer.EnableTraceConsoleListener();
            Tracer.EnableTraceForDebug();
            Hashtable hashtable = new Hashtable();
            string    text      = Environment.GetEnvironmentVariable("CLASSPATH");

            if (text == null || text == "")
            {
                text = ".";
            }
            hashtable["java.class.path"] = text;
            bool   flag  = false;
            bool   flag2 = false;
            bool   flag3 = false;
            bool   flag4 = false;
            bool   flag5 = false;
            string text2 = null;
            int    num   = -1;
            bool   flag6 = false;
            string arg   = null;
            bool   flag7 = false;
            int    result;

            for (int i = 0; i < args.Length; i++)
            {
                string text3 = args[i];
                if (text3[0] != '-')
                {
                    text2 = text3;
                    num   = i + 1;
                    break;
                }
                if (text3 == "-help" || text3 == "-?")
                {
                    break;
                }
                if (text3 == "-Xsave")
                {
                    flag2 = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (text3 == "-XXsave")
                {
                    flag3 = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (text3 == "-Xtime")
                {
                    new IKVM.Helper.Starter.Timer();
                }
                else if (text3 == "-Xwait")
                {
                    flag4 = true;
                }
                else if (text3 == "-Xbreak")
                {
                    Debugger.Break();
                }
                else if (text3 == "-Xnoclassgc")
                {
                    IKVM.Internal.Starter.ClassUnloading = false;
                }
                else if (text3 == "-jar")
                {
                    flag = true;
                }
                else
                {
                    if (text3 == "-version")
                    {
                        Console.WriteLine(Startup.getVersionAndCopyrightInfo());
                        Console.WriteLine();
                        Console.WriteLine("CLR version: {0} ({1} bit)", Environment.Version, IntPtr.Size * 8);
                        System.Type type = System.Type.GetType("Mono.Runtime");
                        if (type != null)
                        {
                            Console.WriteLine("Mono version: {0}", type.InvokeMember("GetDisplayName", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod, null, null, new object[0]));
                        }
                        Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                        for (int j = 0; j < assemblies.Length; j++)
                        {
                            Assembly assembly = assemblies[j];
                            Console.WriteLine("{0}: {1}", assembly.GetName().Name, assembly.GetName().Version);
                        }
                        string property = java.lang.System.getProperty("openjdk.version");
                        if (property != null)
                        {
                            Console.WriteLine("OpenJDK version: {0}", property);
                        }
                        result = 0;
                        return(result);
                    }
                    if (text3 == "-showversion")
                    {
                        flag5 = true;
                    }
                    else if (text3.StartsWith("-D"))
                    {
                        text3 = text3.Substring(2);
                        string[] array = text3.Split(new char[]
                        {
                            '='
                        });
                        string value;
                        if (array.Length == 2)
                        {
                            value = array[1];
                        }
                        else if (array.Length == 1)
                        {
                            value = "";
                        }
                        else
                        {
                            value = text3.Substring(array[0].Length + 1);
                        }
                        hashtable[array[0]] = value;
                    }
                    else if (text3 == "-ea" || text3 == "-enableassertions")
                    {
                        Assertions.EnableAssertions();
                    }
                    else if (text3 == "-da" || text3 == "-disableassertions")
                    {
                        Assertions.DisableAssertions();
                    }
                    else if (text3 == "-esa" || text3 == "-enablesystemassertions")
                    {
                        Assertions.EnableSystemAssertions();
                    }
                    else if (text3 == "-dsa" || text3 == "-disablesystemassertions")
                    {
                        Assertions.DisableSystemAssertions();
                    }
                    else if (text3.StartsWith("-ea:") || text3.StartsWith("-enableassertions:"))
                    {
                        Assertions.EnableAssertions(text3.Substring(text3.IndexOf(':') + 1));
                    }
                    else if (text3.StartsWith("-da:") || text3.StartsWith("-disableassertions:"))
                    {
                        Assertions.DisableAssertions(text3.Substring(text3.IndexOf(':') + 1));
                    }
                    else if (text3 == "-cp" || text3 == "-classpath")
                    {
                        hashtable["java.class.path"] = args[++i];
                    }
                    else if (text3.StartsWith("-Xtrace:"))
                    {
                        Tracer.SetTraceLevel(text3.Substring(8));
                    }
                    else if (text3.StartsWith("-Xmethodtrace:"))
                    {
                        Tracer.HandleMethodTrace(text3.Substring(14));
                    }
                    else if (text3 == "-Xdebug")
                    {
                        flag6 = true;
                    }
                    else if (!(text3 == "-Xnoagent"))
                    {
                        if (text3.StartsWith("-Xrunjdwp") || text3.StartsWith("-agentlib:jdwp"))
                        {
                            arg   = text3;
                            flag6 = true;
                        }
                        else if (text3.StartsWith("-Xreference:"))
                        {
                            Startup.addBootClassPathAssemby(Assembly.LoadFrom(text3.Substring(12)));
                        }
                        else if (text3 == "-Xnoglobbing")
                        {
                            flag7 = true;
                        }
                        else
                        {
                            if (!text3.StartsWith("-Xms") && !text3.StartsWith("-Xmx") && !text3.StartsWith("-Xss") && !(text3 == "-Xmixed") && !(text3 == "-Xint") && !(text3 == "-Xnoclassgc") && !(text3 == "-Xincgc") && !(text3 == "-Xbatch") && !(text3 == "-Xfuture") && !(text3 == "-Xrs") && !(text3 == "-Xcheck:jni") && !(text3 == "-Xshare:off") && !(text3 == "-Xshare:auto") && !(text3 == "-Xshare:on"))
                            {
                                Console.Error.WriteLine("{0}: illegal argument", text3);
                                break;
                            }
                            Console.Error.WriteLine("Unsupported option ignored: {0}", text3);
                        }
                    }
                }
            }
            if (text2 == null || flag5)
            {
                Console.Error.WriteLine(Startup.getVersionAndCopyrightInfo());
                Console.Error.WriteLine();
            }
            if (text2 == null)
            {
                Console.Error.WriteLine("usage: ikvm [-options] <class> [args...]");
                Console.Error.WriteLine("          (to execute a class)");
                Console.Error.WriteLine("    or ikvm -jar [-options] <jarfile> [args...]");
                Console.Error.WriteLine("          (to execute a jar file)");
                Console.Error.WriteLine();
                Console.Error.WriteLine("where options include:");
                Console.Error.WriteLine("    -? -help          Display this message");
                Console.Error.WriteLine("    -version          Display IKVM and runtime version");
                Console.Error.WriteLine("    -showversion      Display version and continue running");
                Console.Error.WriteLine("    -cp -classpath <directories and zip/jar files separated by {0}>", Path.PathSeparator);
                Console.Error.WriteLine("                      Set search path for application classes and resources");
                Console.Error.WriteLine("    -D<name>=<value>  Set a system property");
                Console.Error.WriteLine("    -ea[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("    -enableassertions[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("                      Enable assertions.");
                Console.Error.WriteLine("    -da[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("    -disableassertions[:<packagename>...|:<classname>]");
                Console.Error.WriteLine("                      Disable assertions");
                Console.Error.WriteLine("    -Xsave            Save the generated assembly (for debugging)");
                Console.Error.WriteLine("    -Xtime            Time the execution");
                Console.Error.WriteLine("    -Xtrace:<string>  Displays all tracepoints with the given name");
                Console.Error.WriteLine("    -Xmethodtrace:<string>");
                Console.Error.WriteLine("                      Builds method trace into the specified output methods");
                Console.Error.WriteLine("    -Xwait            Keep process hanging around after exit");
                Console.Error.WriteLine("    -Xbreak           Trigger a user defined breakpoint at startup");
                Console.Error.WriteLine("    -Xnoclassgc       Disable class garbage collection");
                Console.Error.WriteLine("    -Xnoglobbing      Disable argument globbing");
                result = 1;
                return(result);
            }
            try
            {
                if (flag6)
                {
                    Assembly assembly = Assembly.GetExecutingAssembly();
                    string   text4    = arg + " -pid:" + System.Diagnostics.Process.GetCurrentProcess().Id;
                    string   text5    = new FileInfo(assembly.Location).DirectoryName + "\\debugger.exe";
                    try
                    {
                        ProcessStartInfo processStartInfo = new ProcessStartInfo(text5, text4);
                        processStartInfo.UseShellExecute = false;
                        new System.Diagnostics.Process
                        {
                            StartInfo = processStartInfo
                        }.Start();
                    }
                    catch (System.Exception ex)
                    {
                        Console.Error.WriteLine(text5 + " " + text4);
                        throw ex;
                    }
                }
                if (flag)
                {
                    hashtable["java.class.path"] = text2;
                }
                hashtable["sun.java.command"]  = string.Join(" ", args, num - 1, args.Length - (num - 1));
                hashtable["sun.java.launcher"] = "SUN_STANDARD";
                Startup.setProperties(hashtable);
                Startup.enterMainThread();
                string[] array2;
                if (flag7)
                {
                    array2 = new string[args.Length - num];
                    System.Array.Copy(args, num, array2, 0, array2.Length);
                }
                else
                {
                    array2 = Startup.glob(args, num);
                }
                if (flag)
                {
                    text2 = IKVM.Helper.Starter.GetMainClassFromJarManifest(text2);
                    if (text2 == null)
                    {
                        result = 1;
                        return(result);
                    }
                }
                Class clazz = Class.forName(text2, true, ClassLoader.getSystemClassLoader());
                try
                {
                    Method method = IKVM.Internal.Starter.FindMainMethod(clazz);
                    if (method == null)
                    {
                        throw new NoSuchMethodError("main");
                    }
                    if (!Modifier.isPublic(method.getModifiers()))
                    {
                        Console.Error.WriteLine("Main method not public.");
                    }
                    else
                    {
                        method.setAccessible(true);
                        if (flag2)
                        {
                            java.lang.Runtime.getRuntime().addShutdownHook(new IKVM.Helper.Starter.SaveAssemblyShutdownHook(clazz));
                        }
                        if (flag4)
                        {
                            java.lang.Runtime.getRuntime().addShutdownHook(new IKVM.Helper.Starter.WaitShutdownHook());
                        }
                        try
                        {
                            method.invoke(null, new object[]
                            {
                                array2
                            });
                            result = 0;
                            return(result);
                        }
                        catch (InvocationTargetException ex2)
                        {
                            throw ex2.getCause();
                        }
                    }
                }
                finally
                {
                    if (flag3)
                    {
                        IKVM.Internal.Starter.SaveDebugImage();
                    }
                }
            }
            catch (System.Exception t)
            {
                java.lang.Thread thread = java.lang.Thread.currentThread();
                thread.getThreadGroup().uncaughtException(thread, Util.mapException(t));
            }
            finally
            {
                Startup.exitMainThread();
            }
            result = 1;
            return(result);
        }
Example #16
0
        public static void setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
        {

        }
Example #17
0
 /// <summary>
 /// Copies into the specified array every active thread in  the current thread's thread group and its subgroups.
 /// </summary>
 public static int enumerate(Thread[] tarray)
 {
     return default(int);
 }
Example #18
0
    static int Main(string[] args)
    {
        Tracer.EnableTraceConsoleListener();
        Tracer.EnableTraceForDebug();
        System.Collections.Hashtable props = new System.Collections.Hashtable();
        string classpath = Environment.GetEnvironmentVariable("CLASSPATH");

        if (classpath == null || classpath == "")
        {
            classpath = ".";
        }
        props["java.class.path"] = classpath;
        bool   jar           = false;
        bool   saveAssembly  = false;
        bool   saveAssemblyX = false;
        bool   waitOnExit    = false;
        bool   showVersion   = false;
        string mainClass     = null;
        int    vmargsIndex   = -1;
        bool   debug         = false;
        String debugArg      = null;

        for (int i = 0; i < args.Length; i++)
        {
            String arg = args[i];
            if (arg[0] == '-')
            {
                if (arg == "-help" || arg == "-?")
                {
                    break;
                }
                else if (arg == "-Xsave")
                {
                    saveAssembly = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (arg == "-XXsave")
                {
                    saveAssemblyX = true;
                    IKVM.Internal.Starter.PrepareForSaveDebugImage();
                }
                else if (arg == "-Xtime")
                {
                    new Timer();
                }
                else if (arg == "-Xwait")
                {
                    waitOnExit = true;
                }
                else if (arg == "-Xbreak")
                {
                    System.Diagnostics.Debugger.Break();
                }
                else if (arg == "-Xnoclassgc")
                {
                    IKVM.Internal.Starter.ClassUnloading = false;
                }
                else if (arg == "-jar")
                {
                    jar = true;
                }
                else if (arg == "-version")
                {
                    Console.WriteLine(Startup.getVersionAndCopyrightInfo());
                    Console.WriteLine();
                    Console.WriteLine("CLR version: {0} ({1} bit)", Environment.Version, IntPtr.Size * 8);
                    System.Type type = System.Type.GetType("Mono.Runtime");
                    if (type != null)
                    {
                        Console.WriteLine("Mono version: {0}", type.InvokeMember("GetDisplayName", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[0]));
                    }
                    foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        Console.WriteLine("{0}: {1}", asm.GetName().Name, asm.GetName().Version);
                    }
                    string ver = java.lang.System.getProperty("openjdk.version");
                    if (ver != null)
                    {
                        Console.WriteLine("OpenJDK version: {0}", ver);
                    }
                    return(0);
                }
                else if (arg == "-showversion")
                {
                    showVersion = true;
                }
                else if (arg.StartsWith("-D"))
                {
                    arg = arg.Substring(2);
                    string[] keyvalue = arg.Split('=');
                    string   value;
                    if (keyvalue.Length == 2)                    // -Dabc=x
                    {
                        value = keyvalue[1];
                    }
                    else if (keyvalue.Length == 1) // -Dabc
                    {
                        value = "";
                    }
                    else // -Dabc=x=y
                    {
                        value = arg.Substring(keyvalue[0].Length + 1);
                    }
                    props[keyvalue[0]] = value;
                }
                else if (arg == "-ea" || arg == "-enableassertions")
                {
                    IKVM.Runtime.Assertions.EnableAssertions();
                }
                else if (arg == "-da" || arg == "-disableassertions")
                {
                    IKVM.Runtime.Assertions.DisableAssertions();
                }
                else if (arg == "-esa" || arg == "-enablesystemassertions")
                {
                    IKVM.Runtime.Assertions.EnableSystemAssertions();
                }
                else if (arg == "-dsa" || arg == "-disablesystemassertions")
                {
                    IKVM.Runtime.Assertions.DisableSystemAssertions();
                }
                else if (arg.StartsWith("-ea:") || arg.StartsWith("-enableassertions:"))
                {
                    IKVM.Runtime.Assertions.EnableAssertions(arg.Substring(arg.IndexOf(':') + 1));
                }
                else if (arg.StartsWith("-da:") || arg.StartsWith("-disableassertions:"))
                {
                    IKVM.Runtime.Assertions.DisableAssertions(arg.Substring(arg.IndexOf(':') + 1));
                }
                else if (arg == "-cp" || arg == "-classpath")
                {
                    props["java.class.path"] = args[++i];
                }
                else if (arg.StartsWith("-Xtrace:"))
                {
                    Tracer.SetTraceLevel(arg.Substring(8));
                }
                else if (arg.StartsWith("-Xmethodtrace:"))
                {
                    Tracer.HandleMethodTrace(arg.Substring(14));
                }
                else if (arg == "-Xdebug")
                {
                    debug = true;
                }
                else if (arg == "-Xnoagent")
                {
                    //ignore it, disable support for oldjdb
                }
                else if (arg.StartsWith("-Xrunjdwp") || arg.StartsWith("-agentlib:jdwp"))
                {
                    debugArg = arg;
                    debug    = true;
                }
                else if (arg.StartsWith("-Xreference:"))
                {
                    Startup.addBootClassPathAssemby(Assembly.LoadFrom(arg.Substring(12)));
                }
                else if (arg.StartsWith("-Xms") ||
                         arg.StartsWith("-Xmx") ||
                         arg.StartsWith("-Xss") ||
                         arg == "-Xmixed" ||
                         arg == "-Xint" ||
                         arg == "-Xnoclassgc" ||
                         arg == "-Xincgc" ||
                         arg == "-Xbatch" ||
                         arg == "-Xfuture" ||
                         arg == "-Xrs" ||
                         arg == "-Xcheck:jni" ||
                         arg == "-Xshare:off" ||
                         arg == "-Xshare:auto" ||
                         arg == "-Xshare:on"
                         )
                {
                    Console.Error.WriteLine("Unsupported option ignored: {0}", arg);
                }
                else
                {
                    Console.Error.WriteLine("{0}: illegal argument", arg);
                    break;
                }
            }
            else
            {
                mainClass   = arg;
                vmargsIndex = i + 2;
                break;
            }
        }
        if (mainClass == null || showVersion)
        {
            Console.Error.WriteLine(Startup.getVersionAndCopyrightInfo());
            Console.Error.WriteLine();
        }
        if (mainClass == null)
        {
            Console.Error.WriteLine("usage: ikvm [-options] <class> [args...]");
            Console.Error.WriteLine("          (to execute a class)");
            Console.Error.WriteLine("    or ikvm -jar [-options] <jarfile> [args...]");
            Console.Error.WriteLine("          (to execute a jar file)");
            Console.Error.WriteLine();
            Console.Error.WriteLine("where options include:");
            Console.Error.WriteLine("    -? -help          Display this message");
            Console.Error.WriteLine("    -version          Display IKVM and runtime version");
            Console.Error.WriteLine("    -showversion      Display version and continue running");
            Console.Error.WriteLine("    -cp -classpath <directories and zip/jar files separated by {0}>", Path.PathSeparator);
            Console.Error.WriteLine("                      Set search path for application classes and resources");
            Console.Error.WriteLine("    -D<name>=<value>  Set a system property");
            Console.Error.WriteLine("    -ea[:<packagename>...|:<classname>]");
            Console.Error.WriteLine("    -enableassertions[:<packagename>...|:<classname>]");
            Console.Error.WriteLine("                      Enable assertions.");
            Console.Error.WriteLine("    -da[:<packagename>...|:<classname>]");
            Console.Error.WriteLine("    -disableassertions[:<packagename>...|:<classname>]");
            Console.Error.WriteLine("                      Disable assertions");
            Console.Error.WriteLine("    -Xsave            Save the generated assembly (for debugging)");
            Console.Error.WriteLine("    -Xtime            Time the execution");
            Console.Error.WriteLine("    -Xtrace:<string>  Displays all tracepoints with the given name");
            Console.Error.WriteLine("    -Xmethodtrace:<string>");
            Console.Error.WriteLine("                      Builds method trace into the specified output methods");
            Console.Error.WriteLine("    -Xwait            Keep process hanging around after exit");
            Console.Error.WriteLine("    -Xbreak           Trigger a user defined breakpoint at startup");
            Console.Error.WriteLine("    -Xnoclassgc       Disable class garbage collection");
            return(1);
        }
        try
        {
            if (debug)
            {
                // Starting the debugger
                Assembly asm       = Assembly.GetExecutingAssembly();
                String   arguments = debugArg + " -pid:" + System.Diagnostics.Process.GetCurrentProcess().Id;
                String   program   = new FileInfo(asm.Location).DirectoryName + "\\debugger.exe";
                try
                {
                    ProcessStartInfo info = new ProcessStartInfo(program, arguments);
                    info.UseShellExecute = false;
                    Process debugger = new Process();
                    debugger.StartInfo = info;
                    debugger.Start();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(program + " " + arguments);
                    throw ex;
                }
            }
            if (jar)
            {
                props["java.class.path"] = mainClass;
            }
            Startup.setProperties(props);
            Startup.enterMainThread();
            // HACK Starup.glob() uses Java code, so we need to do this after we've initialized
            string[] vmargs = Startup.glob(vmargsIndex);
            if (jar)
            {
                mainClass = GetMainClassFromJarManifest(mainClass);
                if (mainClass == null)
                {
                    return(1);
                }
            }
            java.lang.Class clazz = java.lang.Class.forName(mainClass, true, java.lang.ClassLoader.getSystemClassLoader());
            try
            {
                Method method = IKVM.Internal.Starter.FindMainMethod(clazz);
                if (method == null)
                {
                    throw new java.lang.NoSuchMethodError("main");
                }
                else if (!Modifier.isPublic(method.getModifiers()))
                {
                    Console.Error.WriteLine("Main method not public.");
                }
                else
                {
                    // if clazz isn't public, we can still call main
                    method.setAccessible(true);
                    if (saveAssembly)
                    {
                        java.lang.Runtime.getRuntime().addShutdownHook(new SaveAssemblyShutdownHook(clazz));
                    }
                    if (waitOnExit)
                    {
                        java.lang.Runtime.getRuntime().addShutdownHook(new WaitShutdownHook());
                    }
                    try
                    {
                        method.invoke(null, new object[] { vmargs });
                        return(0);
                    }
                    catch (InvocationTargetException x)
                    {
                        throw x.getCause();
                    }
                }
            }
            finally
            {
                if (saveAssemblyX)
                {
                    IKVM.Internal.Starter.SaveDebugImage();
                }
            }
        }
        catch (System.Exception x)
        {
            java.lang.Thread thread = java.lang.Thread.currentThread();
            thread.getThreadGroup().uncaughtException(thread, ikvm.runtime.Util.mapException(x));
        }
        finally
        {
            Startup.exitMainThread();
        }
        return(1);
    }