From edc572dacf3ff65c5584f8c02bb291abce0c7122 Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 1 Aug 2007 16:50:20 +0000 Subject: Some more work on SceneObject/primitive rewrites (AllNewSceneObjectGroup2 /Part2). Updated the JavaVM to a later version I did (basically some clean up and a little bit more functional). Added SendLoadURL method to IClientAPI. --- .../Engines/JVMEngine/JVM/ClassInstance.cs | 1 + .../scripting/Engines/JVMEngine/JVM/ClassRecord.cs | 239 ++++++++++++++++----- .../Engines/JVMEngine/JVM/Interpreter.Logic.cs | 222 ++++++++++++++----- .../scripting/Engines/JVMEngine/JVM/OpCodes.cs | 56 +++++ 4 files changed, 418 insertions(+), 100 deletions(-) create mode 100644 OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/OpCodes.cs (limited to 'OpenSim/Region/Environment/Scenes/scripting/Engines') diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs index ca729b4..be29ee9 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs @@ -35,6 +35,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public class ClassInstance : Object { public int size; + public ClassRecord ClassRec; public Dictionary Fields = new Dictionary(); public ClassInstance() diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs index f151b7e..a609a40 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs @@ -30,6 +30,7 @@ using System.IO; using System.Collections.Generic; using System.Text; using OpenSim.Region.Scripting.EmbeddedJVM.Types; +using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes; namespace OpenSim.Region.Scripting.EmbeddedJVM { @@ -60,7 +61,11 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public ClassInstance CreateNewInstance() { - return new ClassInstance(); + ClassInstance classInst = new ClassInstance(); + classInst.ClassRec = this; + //TODO: set fields + + return classInst; } public void LoadClassFromFile(string fileName) @@ -75,33 +80,40 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { int i = 0; i += 4; - _minorVersion = (ushort)((data[i++] << 8) + data[i++] ); - _majorVersion = (ushort)((data[i++] << 8) + data[i++] ); - _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] ); - // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); - for (int count = 0; count < _constantPoolCount -1 ; count++) + _minorVersion = (ushort)((data[i++] << 8) + data[i++]); + _majorVersion = (ushort)((data[i++] << 8) + data[i++]); + _constantPoolCount = (ushort)((data[i++] << 8) + data[i++]); + Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); + for (int count = 0; count < (_constantPoolCount - 1); count++) { //read in the constant pool byte pooltype = data[i++]; - //Console.WriteLine("#" +count +": new constant type = " +pooltype); + Console.WriteLine("#" + count + ": new constant type = " + pooltype); //Console.WriteLine("start position is: " + i); switch (pooltype) { case 1: //Utf8 - ushort uLength = (ushort)((data[i++] << 8) + data[i++] ); + ushort uLength = (ushort)((data[i++] << 8) + data[i++]); - // Console.WriteLine("new utf8 type, length is " + uLength); + // Console.WriteLine("new utf8 type, length is " + uLength); PoolUtf8 utf8 = new PoolUtf8(); utf8.readValue(data, ref i, uLength); this._constantsPool.Add(utf8); break; case 3: //Int break; + case 4: //Float + break; case 7: //Class PoolClass pClass = new PoolClass(this); pClass.readValue(data, ref i); this._constantsPool.Add(pClass); break; + case 9: //FieldRef + PoolFieldRef pField = new PoolFieldRef(this); + pField.readValue(data, ref i); + this._constantsPool.Add(pField); + break; case 10: //Method PoolMethodRef pMeth = new PoolMethodRef(this); pMeth.readValue(data, ref i); @@ -115,9 +127,9 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } } - _accessFlags = (ushort)((data[i++] << 8) + data[i++] ); - _thisClass = (ushort)((data[i++] << 8) + data[i++] ); - _supperClass = (ushort)((data[i++] << 8) + data[i++] ); + _accessFlags = (ushort)((data[i++] << 8) + data[i++]); + _thisClass = (ushort)((data[i++] << 8) + data[i++]); + _supperClass = (ushort)((data[i++] << 8) + data[i++]); if (this._constantsPool[this._thisClass - 1] is PoolClass) { @@ -126,8 +138,16 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); //should now read in the info for each interface + _fieldCount = (ushort)((data[i++] << 8) + data[i++]); //should now read in the info for each field + for (int count = 0; count < _fieldCount; count++) + { + FieldInfo fieldInf = new FieldInfo(this); + fieldInf.ReadData(data, ref i); + this._fieldList.Add(fieldInf); + } + _methodCount = (ushort)((data[i++] << 8) + data[i++]); for (int count = 0; count < _methodCount; count++) { @@ -149,9 +169,9 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { for (int count = 0; count < _methodCount; count++) { - if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8) + if (this._constantsPool[this._methodsList[count].NameIndex - 1] is PoolUtf8) { - if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName) + if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value == methodName) { //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); thread.SetPC(this._methodsList[count].CodePointer); @@ -165,8 +185,8 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void PrintToConsole() { Console.WriteLine("Class File:"); - Console.WriteLine("Major version: " + _majorVersion); - Console.WriteLine("Minor version: " + _minorVersion); + Console.WriteLine("Major version: " + _majorVersion); + Console.WriteLine("Minor version: " + _minorVersion); Console.WriteLine("Pool size: " + _constantPoolCount); for (int i = 0; i < _constantsPool.Count; i++) @@ -174,9 +194,15 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._constantsPool[i].Print(); } - Console.WriteLine("Access flags: " + _accessFlags); - Console.WriteLine("This class: " + _thisClass ); - Console.WriteLine("Super class: " + _supperClass); + Console.WriteLine("Access flags: " + _accessFlags); + Console.WriteLine("This class: " + _thisClass); + Console.WriteLine("Super class: " + _supperClass); + + for (int count = 0; count < _fieldCount; count++) + { + Console.WriteLine(); + this._fieldList[count].Print(); + } for (int count = 0; count < _methodCount; count++) { @@ -184,7 +210,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._methodsList[count].Print(); } - Console.WriteLine("class name is " + this.mClass.Name.Value); + Console.WriteLine("class name is " + this.mClass.Name.Value); } public static byte[] ReadFully(Stream stream) @@ -215,32 +241,32 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { public string Value = ""; - public void readValue(byte[] data,ref int pointer , int length) + public void readValue(byte[] data, ref int pointer, int length) { for (int i = 0; i < length; i++) { - int a =(int) data[pointer++]; + int a = (int)data[pointer++]; if ((a & 0x80) == 0) { Value = Value + (char)a; } else if ((a & 0x20) == 0) { - int b = (int) data[pointer++]; - Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); + int b = (int)data[pointer++]; + Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); } else { int b = (int)data[pointer++]; int c = (int)data[pointer++]; - Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); + Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); } } } public override void Print() { - Console.WriteLine("Utf8 type: " + Value); + Console.WriteLine("Utf8 type: " + Value); } } @@ -263,7 +289,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void readValue(byte[] data, ref int pointer) { - namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); + namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); } public override void Print() @@ -271,7 +297,34 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); Console.Write("Class type: " + namePointer); Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); - + + } + } + + public class PoolFieldRef : PoolItem + { + public ushort classPointer = 0; + public ushort nameTypePointer = 0; + public PoolNamedType mNameType; + public PoolClass mClass; + private ClassRecord parent; + + public PoolFieldRef(ClassRecord paren) + { + parent = paren; + } + + public void readValue(byte[] data, ref int pointer) + { + classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); + nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); + } + + public override void Print() + { + this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); + this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); + Console.WriteLine("FieldRef type: " + classPointer + " , " + nameTypePointer); } } @@ -298,7 +351,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); - Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); + Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); } } @@ -317,16 +370,16 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void readValue(byte[] data, ref int pointer) { - namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); - typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); + namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); + typePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); } public override void Print() { - Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]); - Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]); - Console.Write("Named type: " + namePointer + " , " + typePointer ); - Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value); + Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); + Type = ((PoolUtf8)this.parent._constantsPool[typePointer - 1]); + Console.Write("Named type: " + namePointer + " , " + typePointer); + Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); } } @@ -341,7 +394,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public List Attributes = new List(); private ClassRecord parent; public int CodePointer = 0; - + public MethodInfo(ClassRecord paren) { parent = paren; @@ -361,7 +414,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); - for(int i =0; i< AttributeCount; i++) + for (int i = 0; i < AttributeCount; i++) { MethodAttribute attri = new MethodAttribute(this.parent); attri.ReadData(data, ref pointer); @@ -371,11 +424,11 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void Print() { - Console.WriteLine("Method Info Struct: "); - Console.WriteLine("AccessFlags: " + AccessFlags); - Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); - Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value); - Console.WriteLine("Attribute Count:" + AttributeCount); + Console.WriteLine("Method Info Struct: "); + Console.WriteLine("AccessFlags: " + AccessFlags); + Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value); + Console.WriteLine("Attribute Count:" + AttributeCount); for (int i = 0; i < AttributeCount; i++) { this.Attributes[i].Print(); @@ -426,12 +479,12 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void Print() { - Console.WriteLine("Method Attribute: "); - Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); - Console.WriteLine("Length: " + Length); - Console.WriteLine("MaxStack: " + MaxStack); - Console.WriteLine("MaxLocals: " + MaxLocals); - Console.WriteLine("CodeLength: " + CodeLength); + Console.WriteLine("Method Attribute: "); + Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("Length: " + Length); + Console.WriteLine("MaxStack: " + MaxStack); + Console.WriteLine("MaxLocals: " + MaxLocals); + Console.WriteLine("CodeLength: " + CodeLength); for (int i = 0; i < Code.Length; i++) { Console.WriteLine("OpCode #" + i + " is: " + Code[i]); @@ -483,13 +536,97 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } } - private class FieldInfo + + public class FieldInfo { - public void ReadData(byte[] data, ref int i) + public ushort AccessFlags = 0; + public ushort NameIndex = 0; + public string Name = ""; + public ushort DescriptorIndex = 0; + public ushort AttributeCount = 0; + public List Attributes = new List(); + private ClassRecord parent; + + public FieldInfo(ClassRecord paren) { + parent = paren; + } + public void ReadData(byte[] data, ref int pointer) + { + AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); + NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); + DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); + AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); + for (int i = 0; i < AttributeCount; i++) + { + FieldAttribute attri = new FieldAttribute(this.parent); + attri.ReadData(data, ref pointer); + this.Attributes.Add(attri); + } + } + + public void Print() + { + Console.WriteLine("Field Info Struct: "); + Console.WriteLine("AccessFlags: " + AccessFlags); + Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value); + Console.WriteLine("Attribute Count:" + AttributeCount); + //if static, add to static field list + // if (this.AccessFlags == 9) //public and static + if ((this.AccessFlags & 0x08) != 0) + { + switch (((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value) + { + case "I": + Int newin = new Int(); + this.parent.StaticFields.Add(((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value, newin); + break; + case "F": + Float newfl = new Float(); + this.parent.StaticFields.Add(((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value, newfl); + break; + } + + } + for (int i = 0; i < AttributeCount; i++) + { + this.Attributes[i].Print(); + } + } + + public class FieldAttribute + { + public ushort NameIndex = 0; + public string Name = ""; + public Int32 Length = 0; + public byte[] Data; + private ClassRecord parent; + + public FieldAttribute(ClassRecord paren) + { + parent = paren; + } + + public void ReadData(byte[] data, ref int pointer) + { + NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); + Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); + Data = new byte[Length]; + for (int i = 0; i < Length; i++) + { + Data[i] = data[pointer++]; + } + } + + public void Print() + { + Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + } } } + private class AttributeInfo { public void ReadData(byte[] data, ref int i) @@ -500,4 +637,4 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM #endregion } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs index 56135d3..6f8d70c 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs @@ -42,66 +42,66 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM bool result = false; switch (opcode) { - case 2: - Int m_int= new Int(); + case (byte)(byte)OpCode.iconst_m1: + Int m_int = new Int(); m_int.mValue = -1; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 3: - m_int= new Int(); + case (byte)(byte)OpCode.iconst_0: + m_int = new Int(); m_int.mValue = 0; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 4: + case (byte)(byte)OpCode.iconst_1: m_int = new Int(); m_int.mValue = 1; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 5: + case (byte)(byte)OpCode.iconst_2: m_int = new Int(); m_int.mValue = 2; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 6: + case (byte)(byte)OpCode.iconst_3: m_int = new Int(); m_int.mValue = 3; this._mThread.currentFrame.OpStack.Push(m_int); break; - case 7: + case (byte)(byte)OpCode.iconst_4: m_int = new Int(); m_int.mValue = 4; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 8: + case (byte)OpCode.iconst_5: m_int = new Int(); m_int.mValue = 5; this._mThread.currentFrame.OpStack.Push(m_int); result = true; break; - case 11: + case (byte)OpCode.fconst_0: Float m_float = new Float(); m_float.mValue = 0.0f; this._mThread.currentFrame.OpStack.Push(m_float); result = true; break; - case 12: + case (byte)OpCode.fconst_1: m_float = new Float(); m_float.mValue = 1.0f; this._mThread.currentFrame.OpStack.Push(m_float); result = true; break; - case 13: + case (byte)OpCode.fconst_2: m_float = new Float(); m_float.mValue = 2.0f; this._mThread.currentFrame.OpStack.Push(m_float); result = true; break; - case 16: + case (byte)OpCode.bipush: //is this right? this should be pushing a byte onto stack not int? int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]; Int pushInt = new Int(); pushInt.mValue = pushvalue; @@ -109,7 +109,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._mThread.PC++; result = true; break; - case 17: + case (byte)OpCode.sipush: short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); Int pushInt2 = new Int(); pushInt2.mValue = pushvalue2; @@ -117,7 +117,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._mThread.PC += 2; result = true; break; - case 23: + case (byte)OpCode.fload: short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); Float fload = new Float(); if (this._mThread.currentFrame.LocalVariables[findex1] != null) @@ -131,7 +131,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._mThread.PC++; result = true; break; - case 26: + case (byte)OpCode.iload_0: if (this._mThread.currentFrame.LocalVariables[0] != null) { if (this._mThread.currentFrame.LocalVariables[0] is Int) @@ -143,7 +143,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 27: + case (byte)OpCode.iload_1: if (this._mThread.currentFrame.LocalVariables[1] != null) { if (this._mThread.currentFrame.LocalVariables[1] is Int) @@ -155,7 +155,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 34: + case (byte)OpCode.fload_0: if (this._mThread.currentFrame.LocalVariables[0] != null) { if (this._mThread.currentFrame.LocalVariables[0] is Float) @@ -167,7 +167,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 35: + case (byte)OpCode.fload_1: if (this._mThread.currentFrame.LocalVariables[1] != null) { if (this._mThread.currentFrame.LocalVariables[1] is Float) @@ -179,7 +179,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 36: + case (byte)OpCode.fload_2: if (this._mThread.currentFrame.LocalVariables[2] != null) { if (this._mThread.currentFrame.LocalVariables[2] is Float) @@ -191,7 +191,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 37: + case (byte)OpCode.fload_3: if (this._mThread.currentFrame.LocalVariables[3] != null) { if (this._mThread.currentFrame.LocalVariables[3] is Float) @@ -203,8 +203,18 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 56: - short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] )); + case (byte)OpCode.istore: + short findex3 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); + BaseType istor = this._mThread.currentFrame.OpStack.Pop(); + if (istor is Int) + { + this._mThread.currentFrame.LocalVariables[findex3] = (Int)istor; + } + this._mThread.PC++; + result = true; + break; + case (byte)OpCode.fstore: + short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); BaseType fstor = this._mThread.currentFrame.OpStack.Pop(); if (fstor is Float) { @@ -213,7 +223,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM this._mThread.PC++; result = true; break; - case 59: + case (byte)OpCode.istore_0: BaseType baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Int) { @@ -221,7 +231,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 60: + case (byte)OpCode.istore_1: baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Int) { @@ -229,7 +239,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 67: + case (byte)OpCode.fstore_0: baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Float) { @@ -237,7 +247,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 68: + case (byte)OpCode.fstore_1: baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Float) { @@ -245,7 +255,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 69: + case (byte)OpCode.fstore_2: baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Float) { @@ -253,7 +263,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 70: + case (byte)OpCode.fstore_3: baset = this._mThread.currentFrame.OpStack.Pop(); if (baset is Float) { @@ -261,11 +271,11 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 87: + case (byte)OpCode.pop: this._mThread.currentFrame.OpStack.Pop(); result = true; break; - case 98: + case (byte)OpCode.fadd: BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); if (bf1 is Float && bf2 is Float) @@ -276,7 +286,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 102: + case (byte)OpCode.fsub: BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); if (bsf1 is Float && bsf2 is Float) @@ -287,7 +297,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 104: //check the order of the two values off the stack is correct + case (byte)OpCode.imul: //check the order of the two values off the stack is correct BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); if (bs1 is Int && bs2 is Int) @@ -298,18 +308,18 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 132: + case (byte)OpCode.iinc: if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) { if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) { - ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; + ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; } } this._mThread.PC += 2; result = true; break; - case 139: + case (byte)OpCode.f2i: BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); if (conv1 is Float) { @@ -319,7 +329,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 149: + case (byte)OpCode.fcmpl: BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); if (flcom1 is Float && flcom2 is Float) @@ -341,7 +351,49 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 158: + case (byte)OpCode.fcmpg: + flcom2 = this._mThread.currentFrame.OpStack.Pop(); + flcom1 = this._mThread.currentFrame.OpStack.Pop(); + if (flcom1 is Float && flcom2 is Float) + { + Int compres = new Int(); + if (((Float)flcom1).mValue < ((Float)flcom2).mValue) + { + compres.mValue = -1; + } + else if (((Float)flcom1).mValue > ((Float)flcom2).mValue) + { + compres.mValue = 1; + } + else + { + compres.mValue = 0; + } + this._mThread.currentFrame.OpStack.Push(compres); + } + result = true; + break; + case (byte)OpCode.ifge: + short compareoffset2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); + BaseType compe1 = this._mThread.currentFrame.OpStack.Pop(); + if (compe1 is Int) + { + if (((Int)compe1).mValue >= 0) + { + this._mThread.PC += -1 + compareoffset2; + } + else + { + this._mThread.PC += 2; + } + } + else + { + this._mThread.PC += 2; + } + result = true; + break; + case (byte)OpCode.ifle: short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); if (comp1 is Int) @@ -361,7 +413,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 162: + case (byte)OpCode.if_icmpge: short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); @@ -370,8 +422,8 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); if (((Int)bc1).mValue >= ((Int)bc2).mValue) { - // Console.WriteLine("branch compare true , offset is " +compareoffset); - // Console.WriteLine("current PC is " + this._mThread.PC); + // Console.WriteLine("branch compare true , offset is " +compareoffset); + // Console.WriteLine("current PC is " + this._mThread.PC); this._mThread.PC += -1 + compareoffset; //Console.WriteLine("new PC is " + this._mThread.PC); } @@ -387,7 +439,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 164: + case (byte)OpCode.if_icmple: short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); @@ -396,10 +448,10 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); if (((Int)bcl1).mValue <= ((Int)bcl2).mValue) { - // Console.WriteLine("branch compare true , offset is " + compareloffset); - // Console.WriteLine("current PC is " + this._mThread.PC); - this._mThread.PC += -1 + compareloffset; - // Console.WriteLine("new PC is " + this._mThread.PC); + // Console.WriteLine("branch compare true , offset is " + compareloffset); + // Console.WriteLine("current PC is " + this._mThread.PC); + this._mThread.PC += -1 + compareloffset; + // Console.WriteLine("new PC is " + this._mThread.PC); } else { @@ -413,15 +465,87 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM } result = true; break; - case 167: - short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); + case (byte)OpCode._goto: + short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); this._mThread.PC += -1 + offset; result = true; break; + case (byte)OpCode.getstatic: + short fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); + if (this._mThread.currentClass._constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) + { + if (((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) + { + //from this class + if (this._mThread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) + { + if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) + { + Float retFloat = new Float(); + retFloat.mValue = ((Float)this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; + this._mThread.currentFrame.OpStack.Push(retFloat); + } + else if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) + { + Int retInt = new Int(); + retInt.mValue = ((Int)this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; + // Console.WriteLine("getting static field, " + retInt.mValue); + this._mThread.currentFrame.OpStack.Push(retInt); + } + } + } + else + { + //get from a different class + } + } + this._mThread.PC += 2; + result = true; + break; + case (byte)OpCode.putstatic: + fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); + BaseType addstatic = this._mThread.currentFrame.OpStack.Pop(); + if (this._mThread.currentClass._constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) + { + if (((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) + { + // this class + if (this._mThread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) + { + if (addstatic is Float) + { + if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) + { + Float newf = new Float(); + newf.mValue = ((Float)addstatic).mValue; + this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newf; + } + } + else if (addstatic is Int) + { + if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) + { + //Console.WriteLine("setting static field to " + ((Int)addstatic).mValue); + Int newi = new Int(); + newi.mValue = ((Int)addstatic).mValue; + this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newi; + } + } + } + } + else + { + // a different class + } + } + this._mThread.PC += 2; + result = true; + break; + } return result; } } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/OpCodes.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/OpCodes.cs new file mode 100644 index 0000000..22a9f12 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/OpCodes.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.Scripting.EmbeddedJVM +{ + public enum OpCode : byte + { + iconst_m1 = 2, + iconst_0 = 3, + iconst_1 = 4, + iconst_2 = 5, + iconst_3 = 6, + iconst_4 = 7, + iconst_5 = 8, + fconst_0 = 11, + fconst_1 = 12, + fconst_2 = 13, + bipush = 16, + sipush = 17, + fload = 23, + iload_0 = 26, + iload_1 = 27, + fload_0 = 34, + fload_1 = 35, + fload_2 = 36, + fload_3 = 37, + istore = 54, + fstore = 56, + istore_0 = 59, + istore_1 = 60, + istore_2 = 61, + istore_3 = 62, + fstore_0 = 67, + fstore_1 = 68, + fstore_2 = 69, + fstore_3 = 70, + pop = 87, + fadd = 98, + fsub = 102, + imul = 104, + iinc = 132, + f2i = 139, + fcmpl = 149, + fcmpg = 150, + ifge = 156, + ifgt = 157, + ifle = 158, + if_icmpge = 162, + if_icmpgt = 163, + if_icmple = 164, + _goto = 167, + getstatic = 178, + putstatic = 179 + } +} -- cgit v1.1