public static int GetClassObjectAddr(string name) { for (int i = 0; i < name.Length; i++) { if (name[i] != '[') { if (name[i] == 'L') { name = name.Substring(0, i) + name.Substring(i + 1, name.Length - i - 2); } break; } } if (name.Length == 1) { name = JavaHelper.PrimitiveFullName(name); } else { name = name.Replace('/', '.'); } int addr = 0; if (!classObjects.TryGetValue(name, out addr)) { HeapObject classObj = new HeapObject(ClassFileManager.GetClassFile("java/lang/Class")); addr = Heap.AddItem(classObj); classObjects.Add(name, addr); classObj.SetField("name", "Ljava/lang/String;", new FieldReferenceValue(JavaHelper.CreateJavaStringLiteral(name))); } return(addr); }
public static int CreateJavaStringLiteral(string @string) { HeapArray charArray = new HeapArray(@string.ToCharArray(), ClassObjectManager.GetClassObjectAddr("char")); int charArrAddr = Heap.AddItem(charArray); HeapObject stringObj = new HeapObject(ClassFileManager.GetClassFile("java/lang/String")); stringObj.SetField("value", "[C", new FieldReferenceValue(charArrAddr)); int stringObjAddr = Heap.AddItem(stringObj); return(StringPool.Intern(stringObjAddr)); }
static void Main(string[] args) { Stopwatch.Start(); Console.WindowWidth = 180; //%JAVA_HOME%\bin\javap" - s -p -c -verbose Scanner.class > ..\..\..\Scanner.javap ClassFileManager.InitDictionary(@"..\..\..\..\rt\", BaseDirectory + @"build\classes\java\main\"); //Create main thread object ClassFile threadGroupCFile = ClassFileManager.GetClassFile("java/lang/ThreadGroup"); HeapObject threadGroupObj = new HeapObject(threadGroupCFile); int threadGroupAddr = Heap.AddItem(threadGroupObj); ClassFile threadCFile = ClassFileManager.GetClassFile("java/lang/Thread"); HeapObject threadObj = new HeapObject(threadCFile); ThreadManager.ThreadAddr = Heap.AddItem(threadObj); threadObj.SetField("group", "Ljava/lang/ThreadGroup;", threadGroupAddr); threadObj.SetField("priority", "I", 5); ClassFile systemCFile = ClassFileManager.GetClassFile("java/lang/System"); MethodInfo initSystemClassMethod = systemCFile.MethodDictionary[("initializeSystemClass", "()V")];