Пример #1
0
        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);
        }
Пример #2
0
        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));
        }
Пример #3
0
        public HeapArray(Array array, int itemTypeClassObjAddr) : base(ClassFileManager.GetClassFile("java/lang/Object"))
        {
            Array = array;
            ItemTypeClassObjAddr = itemTypeClassObjAddr;

            int doubleClassObject = ClassObjectManager.GetClassObjectAddr("double");
            int longClassObject   = ClassObjectManager.GetClassObjectAddr("long");

            itemSize = itemTypeClassObjAddr == doubleClassObject || itemTypeClassObjAddr == longClassObject ? 8 : 4;
            //data = new Memory<byte>(new byte[]);
            NumOfBytes = 8 + 8 + itemSize * array.GetLength(0);
            Address    = Heap.AllocateMemory(NumOfBytes);
            //ydata = Heap.GetMemorySlice(Address, size);
            ((long)Array.GetLength(0)).AsByteArray().CopyTo(Heap.GetMemorySlice(Address + 8, 8));
            //SetField("length", "I", );
        }
Пример #4
0
        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")];
Пример #5
0
        public static void ThrowJavaException(string type)
        {
            ClassFile exceptionCFile = ClassFileManager.GetClassFile(type);
            int       objRef         = Heap.AddItem(new HeapObject(exceptionCFile));

            MethodInfo initMethod = exceptionCFile.MethodDictionary[("<init>", "()V")];