sa-jdi

ame, int fieldId)
  {
    fields.put(name, new Integer(fieldId));
  }
  
  private static int getFieldID(String name)
  {
    Integer res = (Integer)fields.get(name);
    return res != null ? res.intValue() : -1;
  }
  
  static
  {
    addField("method", 0);
    addField("bci", 1);
    addField("line", 2);
    addField("locals", 3);
    addField("thisObject", 4);
    addField("thread", 5);
  }
  
  private JSJavaObject getMethod()
  {
    return factory.newJSJavaObject(jvf.getMethod());
  }
  
  private int getBCI()
  {
    return jvf.getBCI();
  }
  
  private int getLineNumber()
  {
    int bci = jvf.getBCI();
    if (bci == -1) {
      return 0;
    }
    int lineNum = jvf.getMethod().getLineNumberFromBCI(bci);
    return lineNum <= 0 ? 0 : lineNum;
  }
  
  private synchronized JSMap getLocals()
  {
    Map map;
    StackValueCollection values;
    Method method;
    OopHandle handle;
    ObjectHeap heap;
    Iterator varItr;
    if (localsCache == null)
    {
      map = new HashMap();
      localsCache = factory.newJSMap(map);
      values = jvf.getLocals();
      method = jvf.getMethod();
      if ((method.isNative()) || (!method.hasLocalVariableTable()) || (values == null)) {
        return localsCache;
      }
      LocalVariableTableElement[] localVars = method.getLocalVariableTable();
      int bci = getBCI();
      List visibleVars = new ArrayList(0);
      for (int i = 0; i < localVars.length; i++)
      {
        LocalVariableTableElement cur = localVars[i];
        if ((cur.getStartBCI() >= bci) && (cur.getLength() > 0)) {
          visibleVars.add(cur);
        }
      }
      handle = null;
      heap = VM.getVM().getObjectHeap();
      for (varItr = visibleVars.iterator(); varItr.hasNext();)
      {
        LocalVariableTableElement cur = (LocalVariableTableElement)varItr.next();
        String name = method.getConstants().getSymbolAt(cur.getNameCPIndex()).asString();
        int slot = cur.getSlot();
        
        String signature = method.getConstants().getSymbolAt(cur.getDescriptorCPIndex()).asString();
        BasicType variableType = BasicType.charToBasicType(signature.charAt(0));
        Object value = null;
        if (variableType == BasicType.T_BOOLEAN)
        {
          value = Boolean.valueOf(values.booleanAt(slot));
        }
        else if (variableType == BasicType.T_CHAR)
        {
          value = new Character(values.charAt(slot));
        }
        else if (variableType == BasicType.T_FLOAT)
        {
          value = new Float(values.floatAt(slot));
        }
        else if (variableType == BasicType.T_DOUBLE)
        {
          value = new Double(values.doubleAt(slot));
        }
        else if (variableType == BasicType.T_BYTE)
        {
          value = new Byte(values.byteAt(slot));
        }
        else if (variableType == BasicType.T_SHORT)
        {
          value = new Short(values.shortAt(slot));
        }
        else if (variableType == BasicType.T_INT)
        {
          value = new Integer(values.intAt(slot));
        }
        else if (variableType == BasicType.T_LONG)
        {
          value = new Long(values.longAt(slot));
        }
        else if ((variableType == BasicType.T_OBJECT) || (variableType == BasicType.T_ARRAY))
        {
          handle = values.oopHandleAt(slot);
          value = factory.newJSJavaObject(heap.newOop(handle));
        }
        map.put(name, value);
      }
    }
    return localsCache;
  }
  
  private JSJavaObject getThisObject()
  {
    Method method = jvf.getMethod();
    if (method.isStatic()) {
      return null;
    }
    StackValueCollection values = jvf.getLocals();
    if (values != null)
    {
      OopHandle handle = values.oopHandleAt(0);
      ObjectHeap heap = VM.getVM().getObjectHeap();
      return factory.newJSJavaObject(heap.newOop(handle));
    }
    return null;
  }
  
  private JSJavaThread getThread()
  {
    return factory.newJSJavaThread(jvf.getThread());
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaFrame
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import javax.script.ScriptException;
import sun.jvm.hotspot.oops.DefaultHeapVisitor;
import sun.jvm.hotspot.oops.Oop;

final class JSJavaHeap$1
  extends DefaultHeapVisitor
{
  private final JSJavaHeap this$0;
  
  JSJavaHeap$1(JSJavaHeap paramJSJavaHeap, Callable paramCallable) {}
  
  public boolean doObj(Oop oop)
  {
    JSJavaObject jo = JSJavaHeap.access$000(this$0).newJSJavaObject(oop);
    if (jo != null) {
      try
      {
        val$finalFunc.call(new Object[] { jo });
      }
      catch (ScriptException exp)
      {
        throw new RuntimeException(exp);
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaHeap.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import javax.script.ScriptException;
import sun.jvm.hotspot.memory.SystemDictionary.ClassAndLoaderVisitor;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.Oop;

final class JSJavaHeap$2
  implements SystemDictionary.ClassAndLoaderVisitor
{
  private final JSJavaHeap this$0;
  
  JSJavaHeap$2(JSJavaHeap paramJSJavaHeap, Callable paramCallable) {}
  
  public void visit(Klass kls, Oop loader)
  {
    JSJavaKlass jk = JSJavaHeap.access$000(this$0).newJSJavaKlass(kls);
    if (jk == null) {
      return;
    }
    JSJavaObject k = jk.getJSJavaClass();
    JSJavaObject l = JSJavaHeap.access$000(this$0).newJSJavaObject(loader);
    if ((k != null) && 
      (k != null)) {
      try
      {
        val$finalFunc.call(new Object[] { k, l });
      }
      catch (ScriptException exp)
      {
        throw new RuntimeException(exp);
      }
    }
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaHeap.2
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import javax.script.ScriptException;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.oops.Klass;

final class JSJavaHeap$3
  implements SystemDictionary.ClassVisitor
{
  private final JSJavaHeap this$0;
  
  JSJavaHeap$3(JSJavaHeap paramJSJavaHeap, Callable paramCallable) {}
  
  public void visit(Klass kls)
  {
    JSJavaKlass jk = JSJavaHeap.access$000(this$0).newJSJavaKlass(kls);
    if (jk == null) {
      return;
    }
    JSJavaClass k = jk.getJSJavaClass();
    if ((k != null) && 
      (k != null)) {
      try
      {
        val$finalFunc.call(new Object[] { k });
      }
      catch (ScriptException exp)
      {
        throw new RuntimeException(exp);
      }
    }
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaHeap.3
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.script.ScriptException;
import sun.jvm.hotspot.gc_interface.CollectedHeap;
import sun.jvm.hotspot.memory.SystemDictionary;
import sun.jvm.hotspot.memory.SystemDictionary.ClassAndLoaderVisitor;
import sun.jvm.hotspot.memory.SystemDictionary.ClassVisitor;
import sun.jvm.hotspot.memory.Universe;
import sun.jvm.hotspot.oops.DefaultHeapVisitor;
import sun.jvm.hotspot.oops.HeapVisitor;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.ObjectHeap;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;

public class JSJavaHeap
  extends DefaultScriptObject
{
  private static final int FIELD_CAPACITY = 0;
  private static final int FIELD_USED = 1;
  private static final int FIELD_FOR_EACH_OBJECT = 2;
  private static final int FIELD_FOR_EACH_CLASS = 3;
  private static final int FIELD_UNDEFINED = -1;
  
  public JSJavaHeap(JSJavaFactory fac)
  {
    factory = fac;
  }
  
  public Object get(String name)
  {
    int fieldID = getFieldID(name);
    switch (fieldID)
    {
    case 0: 
      return new Long(getCapacity());
    case 1: 
      return new Long(getUsed());
    case 2: 
      return new MethodCallable(this, forEachObjectMethod);
    case 3: 
      return new MethodCallable(this, forEachClassMethod);
    }
    return super.get(name);
  }
  
  public Object[] getIds()
  {
    Object[] superIds = super.getIds();
    Object[] tmp = fields.keySet().toArray();
    Object[] res = new Object[superIds.length + tmp.length];
    System.arraycopy(tmp, 0, res, 0, tmp.length);
    System.arraycopy(superIds, 0, res, tmp.length, superIds.length);
    return res;
  }
  
  public boolean has(String name)
  {
    if (getFieldID(name) != -1) {
      return true;
    }
    return super.has(name);
  }
  
  public void put(String name, Object value)
  {
    if (getFieldID(name) == -1) {
      super.put(name, value);
    }
  }
  
  public void forEachObject(Object[] args)
  {
    boolean subtypes = true;
    Klass kls = null;
    Callable func = null;
    switch (args.length)
    {
    case 3: 
      Object b = args[2];
      if ((b != null) && ((b instanceof Boolean))) {
        subtypes = ((Boolean)b).booleanValue();
      }
    case 2: 
      Object k = args[1];
      if (k == null) {
        return;
      }
      if ((k instanceof JSJavaKlass))
      {
        kls = ((JSJavaKlass)k).getKlass();
      }
      else if ((k instanceof String))
      {
        kls = SystemDictionaryHelper.findInstanceKlass((String)k);
        if (kls == null) {
          return;
        }
      }
    case 1: 
      Object f = args[0];
      if ((f != null) && ((f instanceof Callable))) {
        func = (Callable)f;
      } else {
        return;
      }
      break;
    }
    return;
    
    final Callable finalFunc = func;
    HeapVisitor visitor = new DefaultHeapVisitor()
    {
      public boolean doObj(Oop oop)
      {
        JSJavaObject jo = factory.newJSJavaObject(oop);
        if (jo != null) {
          try
          {
            finalFunc.call(new Object[] { jo });
          }
          catch (ScriptException exp)
          {
            throw new RuntimeException(exp);
          }
        }
        return false;
      }
    };
    ObjectHeap heap = VM.getVM().getObjectHeap();
    if (kls == null) {
      kls = SystemDictionaryHelper.findInstanceKlass("java.lang.Object");
    }
    heap.iterateObjectsOfKlass(visitor, kls, subtypes);
  }
  
  public void forEachClass(Object[] args)
  {
    boolean withLoader = false;
    Callable func = null;
    switch (args.length)
    {
    case 2: 
      Object b = args[1];
      if ((b instanceof Boolean)) {
        withLoader = ((Boolean)b).booleanValue();
      }
    case 1: 
      Object f = args[0];
      if ((f instanceof Callable)) {
        func = (Callable)f;
      } else {
        return;
      }
      break;
    }
    return;
    
    final Callable finalFunc = func;
    SystemDictionary sysDict = VM.getVM().getSystemDictionary();
    if (withLoader) {
      sysDict.classesDo(new SystemDictionary.ClassAndLoaderVisitor()
      {
        public void visit(Klass kls, Oop loader)
        {
          JSJavaKlass jk = factory.newJSJavaKlass(kls);
          if (jk == null) {
            return;
          }
          JSJavaObject k = jk.getJSJavaClass();
          JSJavaObject l = factory.newJSJavaObject(loader);
          if ((k != null) && 
            (k != null)) {
            try
            {
              finalFunc.call(new Object[] { k, l });
            }
            catch (ScriptException exp)
            {
              throw new RuntimeException(exp);
            }
          }
        }
      });
    } else {
      sysDict.classesDo(new SystemDictionary.ClassVisitor()
      {
        public void visit(Klass kls)
        {
          JSJavaKlass jk = factory.newJSJavaKlass(kls);
          if (jk == null) {
            return;
          }
          JSJavaClass k = jk.getJSJavaClass();
          if ((k != null) && 
            (k != null)) {
            try
            {
              finalFunc.call(new Object[] { k });
            }
            catch (ScriptException exp)
            {
              throw new RuntimeException(exp);
            }
          }
        }
      });
    }
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("Java Heap (capacity=");
    buf.append(getCapacity());
    buf.append(", used=");
    buf.append(getUsed());
    buf.append(")");
    return buf.toString();
  }
  
  private static Map fields = new HashMap();
  private final JSJavaFactory factory;
  private static Method forEachObjectMethod;
  private static Method forEachClassMethod;
  
  private static void addField(String name, int fieldId)
  {
    fields.put(name, new Integer(fieldId));
  }
  
  private static int getFieldID(String name)
  {
    Integer res = (Integer)fields.get(name);
    return res != null ? res.intValue() : -1;
  }
  
  static
  {
    addField("capacity", 0);
    addField("used", 1);
    addField("forEachObject", 2);
    addField("forEachClass", 3);
    try
    {
      Class myClass = JSJavaHeap.class;
      forEachObjectMethod = myClass.getMethod("forEachObject", new Class[] { new Object[0].getClass() });
      
      forEachClassMethod = myClass.getMethod("forEachClass", new Class[] { new Object[0].getClass() });
    }
    catch (RuntimeException re)
    {
      throw re;
    }
    catch (Exception exp)
    {
      throw new RuntimeException(exp);
    }
  }
  
  private long getCapacity()
  {
    return VM.getVM().getUniverse().heap().capacity();
  }
  
  private long getUsed()
  {
    return VM.getVM().getUniverse().heap().used();
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaHeap
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import sun.jvm.hotspot.oops.Instance;

public class JSJavaInstance
  extends JSJavaObject
{
  protected final JSJavaInstanceKlass type;
  
  public JSJavaInstance(Instance instance, JSJavaFactory fac)
  {
    super(instance, fac);
    type = ((JSJavaInstanceKlass)fac.newJSJavaKlass(instance.getKlass()));
  }
  
  public final Instance getInstance()
  {
    return (Instance)getOop();
  }
  
  public final JSJavaClass getJSJavaClass()
  {
    return type.getJSJavaClass();
  }
  
  public Object get(String name)
  {
    if (hasField(name)) {
      return getFieldValue(name);
    }
    return super.get(name);
  }
  
  public Object[] getIds()
  {
    String[] fieldNames = getFieldNames();
    Object[] superFields = super.getIds();
    Object[] res = new Object[fieldNames.length + superFields.length];
    System.arraycopy(fieldNames, 0, res, 0, fieldNames.length);
    System.arraycopy(superFields, 0, res, fieldNames.length, superFields.length);
    return res;
  }
  
  public boolean has(String name)
  {
    if (hasField(name)) {
      return true;
    }
    return super.has(name);
  }
  
  public void put(String name, Object value)
  {
    if (!hasField(name)) {
      super.put(name, value);
    }
  }
  
  protected Object getFieldValue(String name)
  {
    try
    {
      return type.getInstanceFieldValue(name, getInstance());
    }
    catch (NoSuchFieldException exp) {}
    return UNDEFINED;
  }
  
  protected String[] getFieldNames()
  {
    return type.getInstanceFieldNames();
  }
  
  protected boolean hasField(String name)
  {
    return type.hasInstanceField(name);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaInstance
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import sun.jvm.hotspot.oops.AccessFlags;
import sun.jvm.hotspot.oops.BooleanField;
import sun.jvm.hotspot.oops.ByteField;
import sun.jvm.hotspot.oops.CharField;
import sun.jvm.hotspot.oops.DoubleField;
import sun.jvm.hotspot.oops.Field;
import sun.jvm.hotspot.oops.FieldIdentifier;
import sun.jvm.hotspot.oops.FieldType;
import sun.jvm.hotspot.oops.FloatField;
import sun.jvm.hotspot.oops.Instance;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.IntField;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.LongField;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.oops.OopField;
import sun.jvm.hotspot.oops.ShortField;
import sun.jvm.hotspot.oops.Symbol;
import sun.jvm.hotspot.utilities.Assert;

public class JSJavaInstanceKlass
  extends JSJavaKlass
{
  private static final int FIELD_SOURCE_FILE = 1;
  private static final int FIELD_INTERFACES = 2;
  private static final int FIELD_FIELDS = 3;
  private static final int FIELD_METHODS = 4;
  private static final int FIELD_IS_PRIVATE = 5;
  private static final int FIELD_IS_PUBLIC = 6;
  private static final int FIELD_IS_PROTECTED = 7;
  private static final int FIELD_IS_PACKAGE_PRIVATE = 8;
  private static final int FIELD_IS_STATIC = 9;
  private static final int FIELD_IS_FINAL = 10;
  private static final int FIELD_IS_ABSTRACT = 11;
  private static final int FIELD_IS_STRICT = 12;
  private static final int FIELD_IS_SYNTHETIC = 13;
  private static final int FIELD_IS_INTERFACE = 14;
  private static final int FIELD_CLASS_LOADER = 15;
  private static final int FIELD_PROTECTION_DOMAIN = 16;
  private static final int FIELD_SIGNERS = 17;
  private static final int FIELD_STATICS = 18;
  private static final int FIELD_UNDEFINED = -1;
  
  public JSJavaInstanceKlass(InstanceKlass kls, JSJavaFactory fac)
  {
    super(kls, fac);
    instanceFields = new HashMap();
    staticFields = new HashMap();
  }
  
  public final InstanceKlass getInstanceKlass()
  {
    return (InstanceKlass)getKlass();
  }
  
  public Object getMetaClassFieldValue(String name)
  {
    int fieldID = getFieldID(name);
    InstanceKlass ik = getInstanceKlass();
    switch (fieldID)
    {
    case 1: 
      Symbol sourceFile = ik.getSourceFileName();
      return sourceFile != null ? sourceFile.asString() : "<unknown>";
    case 2: 
      return getInterfaces();
    case 3: 
      return factory.newJSList(ik.getImmediateFields());
    case 4: 
      return factory.newJSList(ik.getImmediateMethods());
    case 5: 
      return Boolean.valueOf(getAccessFlags().isPrivate());
    case 6: 
      return Boolean.valueOf(getAccessFlags().isPublic());
    case 7: 
      return Boolean.valueOf(getAccessFlags().isProtected());
    case 8: 
      AccessFlags acc = getAccessFlags();
      return Boolean.valueOf((!acc.isPrivate()) && (!acc.isPublic()) && (!acc.isProtected()));
    case 9: 
      return Boolean.valueOf(getAccessFlags().isStatic());
    case 10: 
      return Boolean.valueOf(getAccessFlags().isFinal());
    case 11: 
      return Boolean.valueOf(getAccessFlags().isAbstract());
    case 12: 
      return Boolean.valueOf(getAccessFlags().isStrict());
    case 13: 
      return Boolean.valueOf(getAccessFlags().isSynthetic());
    case 14: 
      return Boolean.valueOf(ik.isInterface());
    case 15: 
      return factory.newJSJavaObject(ik.getClassLoader());
    case 16: 
      return factory.newJSJavaObject(ik.getProtectionDomain());
    case 17: 
      return factory.newJSJavaObject(ik.getSigners());
    case 18: 
      return getStatics();
    }
    return super.getMetaClassFieldValue(name);
  }
  
  public boolean hasMetaClassField(String name)
  {
    if (getFieldID(name) != -1) {
      return true;
    }
    return super.hasMetaClassField(name);
  }
  
  public String getName()
  {
    return getInstanceKlass().getName().asString().replace('/', '.');
  }
  
  public boolean isArray()
  {
    return false;
  }
  
  public String[] getMetaClassFieldNames()
  {
    String[] superFields = super.getMetaClassFieldNames();
    Set k = fields.keySet();
    String[] res = new String[k.size() + superFields.length];
    System.arraycopy(superFields, 0, res, 0, superFields.length);
    int i = superFields.length;
    for (Iterator itr = k.iterator(); itr.hasNext();)
    {
      res[i] = ((String)itr.next());
      i++;
    }
    return res;
  }
  
  public Object getInstanceFieldValue(String name, Instance instance)
    throws NoSuchFieldException
  {
    Field fld = findInstanceField(name);
    if (fld != null) {
      return getFieldValue(fld, name, instance);
    }
    throw new NoSuchFieldException(name + " is not field of " + getInstanceKlass().getName().asString().replace('/', '.'));
  }
  
  public Object getStaticFieldValue(String name)
    throws NoSuchFieldException
  {
    Field fld = findStaticField(name);
    if (fld != null) {
      return getFieldValue(fld, name, getInstanceKlass());
    }
    throw new NoSuchFieldException(name + " is not field of " + getInstanceKlass().getName().asString().replace('/', '.'));
  }
  
  public String[] getInstanceFieldNames()
  {
    if (instanceFieldNames == null)
    {
      InstanceKlass current = getInstanceKlass();
      while (current != null)
      {
        List tmp = current.getImmediateFields();
        for (Iterator itr = tmp.iterator(); itr.hasNext();)
        {
          Field fld = (Field)itr.next();
          if (!fld.isStatic())
          {
            String name = fld.getID().getName();
            if (instanceFields.get(name) == null) {
              instanceFields.put(name, fld);
            }
          }
        }
        current = (InstanceKlass)current.getSuper();
      }
      Set s = instanceFields.keySet();
      instanceFieldNames = new String[s.size()];
      int i = 0;
      for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
        instanceFieldNames[i] = ((String)itr.next());
      }
    }
    return instanceFieldNames;
  }
  
  public boolean hasInstanceField(String name)
  {
    Field fld = findInstanceField(name);
    return fld != null;
  }
  
  public String[] getStaticFieldNames()
  {
    if (staticFieldNames == null)
    {
      InstanceKlass current = getInstanceKlass();
      List tmp = current.getImmediateFields();
      for (Iterator itr = tmp.iterator(); itr.hasNext();)
      {
        Field fld = (Field)itr.next();
        if (fld.isStatic()) {
          staticFields.put(fld.getID().getName(), fld);
        }
      }
      Set s = staticFields.keySet();
      staticFieldNames = new String[s.size()];
      int i = 0;
      for (Iterator itr = s.iterator(); itr.hasNext(); i++) {
        staticFieldNames[i] = ((String)itr.next());
      }
    }
    return staticFieldNames;
  }
  
  public boolean hasStaticField(String name)
  {
    Field fld = findStaticField(name);
    return fld != null;
  }
  
  private static Map fields = new HashMap();
  private Map instanceFields;
  private Map staticFields;
  private String[] instanceFieldNames;
  private String[] staticFieldNames;
  private AccessFlags accFlags;
  
  private static void addField(String name, int fieldId)
  {
    fields.put(name, new Integer(fieldId));
  }
  
  private static int getFieldID(String name)
  {
    Integer res = (Integer)fields.get(name);
    return res != null ? res.intValue() : -1;
  }
  
  static
  {
    addField("sourceFile", 1);
    addField("interfaces", 2);
    addField("fields", 3);
    addField("methods", 4);
    addField("isPrivate", 5);
    addField("isPublic", 6);
    addField("isProtected", 7);
    addField("isPackagePrivate", 8);
    addField("isStatic", 9);
    addField("isFinal", 10);
    addField("isAbstract", 11);
    addField("isStrict", 12);
    addField("isSynthetic", 13);
    addField("isInterface", 14);
    addField("classLoader", 15);
    addField("protectionDomain", 16);
    addField("signers", 17);
    addField("statics", 18);
  }
  
  private AccessFlags getAccessFlags()
  {
    if (accFlags == null) {
      accFlags = new AccessFlags(getInstanceKlass().computeModifierFlags());
    }
    return accFlags;
  }
  
  private Object getFieldValue(Field fld, String name, Oop oop)
  {
    FieldType fd = fld.getFieldType();
    if ((fd.isObject()) || (fd.isArray())) {
      return factory.newJSJavaObject(((OopField)fld).getValue(oop));
    }
    if (fd.isByte()) {
      return new Byte(((ByteField)fld).getValue(oop));
    }
    if (fd.isChar()) {
      return new String(new char[] { ((CharField)fld).getValue(oop) });
    }
    if (fd.isDouble()) {
      return new Double(((DoubleField)fld).getValue(oop));
    }
    if (fd.isFloat()) {
      return new Float(((FloatField)fld).getValue(oop));
    }
    if (fd.isInt()) {
      return new Integer(((IntField)fld).getValue(oop));
    }
    if (fd.isLong()) {
      return new Long(((LongField)fld).getValue(oop));
    }
    if (fd.isShort()) {
      return new Short(((ShortField)fld).getValue(oop));
    }
    if (fd.isBoolean()) {
      return Boolean.valueOf(((BooleanField)fld).getValue(oop));
    }
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(false, "invalid field type for " + name);
    }
    return null;
  }
  
  private Field findInstanceField(String name)
  {
    Field fld = (Field)instanceFields.get(name);
    if (fld != null) {
      return fld;
    }
    InstanceKlass current = getInstanceKlass();
    while (current != null)
    {
      List tmp = current.getImmediateFields();
      for (Iterator itr = tmp.iterator(); itr.hasNext();)
      {
        fld = (Field)itr.next();
        if ((fld.getID().getName().equals(name)) && (!fld.isStatic()))
        {
          instanceFields.put(name, fld);
          return fld;
        }
      }
      current = (InstanceKlass)current.getSuper();
    }
    return null;
  }
  
  private Field findStaticField(String name)
  {
    Field fld = (Field)staticFields.get(name);
    if (fld != null) {
      return fld;
    }
    InstanceKlass current = getInstanceKlass();
    List tmp = current.getImmediateFields();
    for (Iterator itr = tmp.iterator(); itr.hasNext();)
    {
      fld = (Field)itr.next();
      if ((fld.getID().getName().equals(name)) && (fld.isStatic()))
      {
        staticFields.put(name, fld);
        return fld;
      }
    }
    return null;
  }
  
  private JSList getInterfaces()
  {
    InstanceKlass ik = getInstanceKlass();
    List intfs = ik.getDirectImplementedInterfaces();
    List res = new ArrayList(0);
    for (Iterator itr = intfs.iterator(); itr.hasNext();)
    {
      Klass k = (Klass)itr.next();
      res.add(k.getJavaMirror());
    }
    return factory.newJSList(res);
  }
  
  private JSMap getStatics()
  {
    String[] names = getStaticFieldNames();
    Map map = new HashMap();
    for (int i = 0; i < names.length; i++) {
      try
      {
        map.put(names[i], getStaticFieldValue(names[i]));
      }
      catch (NoSuchFieldException exp) {}
    }
    return factory.newJSMap(map);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaInstanceKlass
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import java.util.HashMap;
import java.util.Map;
import sun.jvm.hotspot.oops.Klass;

public abstract class JSJavaKlass
{
  private static final int FIELD_SUPER_CLASS = 0;
  private static final int FIELD_NAME = 1;
  private static final int FIELD_IS_ARRAY_CLASS = 2;
  private static final int FIELD_UNDEFINED = -1;
  
  public JSJavaKlass(Klass klass, JSJavaFactory factory)
  {
    this.factory = factory;
    this.klass = klass;
  }
  
  public final Klass getKlass()
  {
    return klass;
  }
  
  public JSJavaClass getJSJavaClass()
  {
    return (JSJavaClass)factory.newJSJavaObject(getKlass().getJavaMirror());
  }
  
  public Object getMetaClassFieldValue(String name)
  {
    int fieldID = getFieldID(name);
    switch (fieldID)
    {
    case 0: 
      JSJavaKlass jk = factory.newJSJavaKlass(getKlass().getSuper());
      return jk != null ? jk.getJSJavaClass() : null;
    case 1: 
      return getName();
    case 2: 
      return Boolean.valueOf(isArray());
    }
    return ScriptObject.UNDEFINED;
  }
  
  public boolean hasMetaClassField(String name)
  {
    return getFieldID(name) != -1;
  }
  
  public String[] getMetaClassFieldNames()
  {
    String[] res = { "name", "superClass", "isArrayClass" };
    return res;
  }
  
  private static Map fields = new HashMap();
  protected final JSJavaFactory factory;
  private final Klass klass;
  
  public abstract String getName();
  
  public abstract boolean isArray();
  
  private static void addField(String name, int fieldId)
  {
    fields.put(name, new Integer(fieldId));
  }
  
  private static int getFieldID(String name)
  {
    Integer res = (Integer)fields.get(name);
    return res != null ? res.intValue() : -1;
  }
  
  static
  {
    addField("base", 0);
    addField("baseClass", 0);
    addField("superClass", 0);
    addField("name", 1);
    addField("isArrayClass", 2);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaKlass
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.Method;
import sun.jvm.hotspot.oops.Symbol;

public class JSJavaMethod
  extends JSJavaObject
{
  private static final int FIELD_NAME = 0;
  private static final int FIELD_SIGNATURE = 1;
  private static final int FIELD_HOLDER = 2;
  private static final int FIELD_IS_PRIVATE = 3;
  private static final int FIELD_IS_PUBLIC = 4;
  private static final int FIELD_IS_PROTECTED = 5;
  private static final int FIELD_IS_PACKAGE_PRIVATE = 6;
  private static final int FIELD_IS_STATIC = 7;
  private static final int FIELD_IS_FINAL = 8;
  private static final int FIELD_IS_SYNCHRONIZED = 9;
  private static final int FIELD_IS_NATIVE = 10;
  private static final int FIELD_IS_ABSTRACT = 11;
  private static final int FIELD_IS_STRICT = 12;
  private static final int FIELD_IS_SYNTHETIC = 13;
  private static final int FIELD_IS_OBSOLETE = 14;
  private static final int FIELD_UNDEFINED = -1;
  
  public JSJavaMethod(Method m, JSJavaFactory fac)
  {
    super(m, fac);
  }
  
  public final Method getMethod()
  {
    return (Method)getOop();
  }
  
  public Object get(String name)
  {
    int fieldID = getFieldID(name);
    Method method = getMethod();
    switch (fieldID)
    {
    case 0: 
      return method.getName().asString();
    case 1: 
      return method.getSignature().asString();
    case 2: 
      return getMethodHolder();
    case 3: 
      return Boolean.valueOf(method.isPrivate());
    case 4: 
      return Boolean.valueOf(method.isPublic());
    case 5: 
      return Boolean.valueOf(method.isProtected());
    case 6: 
      return Boolean.valueOf(method.isPackagePrivate());
    case 7: 
      return Boolean.valueOf(method.isStatic());
    case 8: 
      return Boolean.valueOf(method.isFinal());
    case 9: 
      return Boolean.valueOf(method.isSynchronized());
    case 10: 
      return Boolean.valueOf(method.isNative());
    case 11: 
      return Boolean.valueOf(method.isAbstract());
    case 12: 
      return Boolean.valueOf(method.isStrict());
    case 13: 
      return Boolean.valueOf(method.isSynthetic());
    case 14: 
      return Boolean.valueOf(method.isObsolete());
    }
    return super.get(name);
  }
  
  public Object[] getIds()
  {
    Object[] fieldNames = fields.keySet().toArray();
    Object[] superFields = super.getIds();
    Object[] res = new Object[fieldNames.length + superFields.length];
    System.arraycopy(fieldNames, 0, res, 0, fieldNames.length);
    System.arraycopy(superFields, 0, res, fieldNames.length, superFields.length);
    return res;
  }
  
  public boolean has(String name)
  {
    if (getFieldID(name) != -1) {
      return true;
    }
    return super.has(name);
  }
  
  public void put(String name, Object value)
  {
    if (getFieldID(name) != -1) {
      return;
    }
    super.put(name, value);
  }
  
  public String toString()
  {
    StringBuffer buf = new StringBuffer();
    buf.append("Method ");
    buf.append(getMethod().externalNameAndSignature());
    return buf.toString();
  }
  
  private JSJavaObject getMethodHolder()
  {
    Klass k = getMethod().getMethodHolder();
    return factory.newJSJavaKlass(k).getJSJavaClass();
  }
  
  private static Map fields = new HashMap();
  
  private static void addField(String name, int fieldId)
  {
    fields.put(name, new Integer(fieldId));
  }
  
  private static int getFieldID(String name)
  {
    Integer res = (Integer)fields.get(name);
    return res != null ? res.intValue() : -1;
  }
  
  static
  {
    addField("name", 0);
    addField("signature", 1);
    addField("holder", 2);
    addField("isPrivate", 3);
    addField("isPublic", 4);
    addField("isProtected", 5);
    addField("isPackagePrivate", 6);
    addField("isStatic", 7);
    addField("isFinal", 8);
    addField("isSynchronized", 9);
    addField("isNative", 10);
    addField("isAbstract", 11);
    addField("isStrict", 12);
    addField("isSynthetic", 13);
    addField("isObsolete", 14);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaMethod
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import sun.jvm.hotspot.oops.ObjArray;

public class JSJavaObjArray
  extends JSJavaArray
{
  public JSJavaObjArray(ObjArray array, JSJavaFactory fac)
  {
    super(array, fac);
  }
  
  public final ObjArray getObjArray()
  {
    return (ObjArray)getArray();
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaObjArray
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import sun.jvm.hotspot.oops.Array;
import sun.jvm.hotspot.oops.Klass;
import sun.jvm.hotspot.oops.ObjArray;
import sun.jvm.hotspot.oops.ObjArrayKlass;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.oops.TypeArrayKlass;

public class JSJavaObjArrayKlass
  extends JSJavaArrayKlass
{
  public JSJavaObjArrayKlass(ObjArrayKlass kls, JSJavaFactory fac)
  {
    super(kls, fac);
  }
  
  public ObjArrayKlass getObjArrayKlass()
  {
    return (ObjArrayKlass)getArrayKlass();
  }
  
  public String getName()
  {
    Klass botKls = getObjArrayKlass().getBottomKlass();
    int dimension = (int)getObjArrayKlass().getDimension();
    StringBuffer buf = new StringBuffer();
    if ((botKls instanceof TypeArrayKlass)) {
      dimension--;
    }
    buf.append(factory.newJSJavaKlass(botKls).getName());
    for (int i = 0; i < dimension; i++) {
      buf.append("[]");
    }
    return buf.toString();
  }
  
  public Object getFieldValue(int index, Array array)
  {
    Oop obj = ((ObjArray)array).getObjAt(index);
    return factory.newJSJavaObject(obj);
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaObjArrayKlass
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import sun.jvm.hotspot.oops.Oop;

public abstract class JSJavaObject
  extends DefaultScriptObject
{
  private final Oop oop;
  protected final JSJavaFactory factory;
  
  public JSJavaObject(Oop oop, JSJavaFactory factory)
  {
    this.oop = oop;
    this.factory = factory;
  }
  
  public final Oop getOop()
  {
    return oop;
  }
  
  public boolean equals(Object o)
  {
    if ((o == null) || (!(o instanceof JSJavaObject))) {
      return false;
    }
    JSJavaObject other = (JSJavaObject)o;
    return oop.equals(oop);
  }
  
  public int hashCode()
  {
    return oop.hashCode();
  }
  
  public String toString()
  {
    return "Object " + oop.getHandle().toString();
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.utilities.soql.JSJavaObject
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.utilities.soql;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.JVMDebugger;
import sun.jvm.hotspot.oops.InstanceKlass;
import sun.jvm.hotspot.oops.Mark;
import sun.jvm.hotspot.oops.ObjectHeap;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.oops.Symbol;
import sun.jvm.hotspot.runtime.BasicLock;
import sun.jvm.hotspot.runtime.ObjectMonitor;
import sun.jvm.hotspot.runtime.Threads;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.tools.JMap;
import sun.jvm.hotspot.tools.jcore.ClassWriter;
import sun.jvm.hotspot.utilities.ObjectReader;
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;

public abstract class JSJavaScriptEngine
  extends MapScriptObject
{
  private BufferedReader inReader;
  protected final boolean debug;
  private boolean quitting;
  private ScriptEngine engine;
  
  public void startConsole()
  {
    start(true);
  }
  
  public void start()
  {
    start(false);
  }
  
  public void defineFunction(Object target, Method method)
  {
    putFunction(target, method, false);
  }
  
  public Object call(String name, Object[] args)
  {
    Invocable invocable = (Invocable)engine;
    try
    {
      return invocable.invokeFunction(name, args);
    }
    catch (RuntimeException re)
    {
      throw re;
    }
    catch (Exception exp)
    {
      throw new RuntimeException(exp);
    }
  }
  
  public Object address(Object[] args)
  {
    if (args.length != 1) {
      return UNDEFINED;
    }
    Object o = args[0];
    if ((o != null) && ((o instanceof JSJavaObject))) {
      return ((JSJavaObject)o).getOop().getHandle().toString();
    }
    return UNDEFINED;
  }
  
  public Object classof(Object[] args)
  {
    if (args.length != 1) {
      return UNDEFINED;
    }
    Object o = args[0];
    if (o != null)
    {
      if ((o instanceof JSJavaObject))
      {
        if ((o instanceof JSJavaInstance)) {
          return ((JSJavaInstance)o).getJSJavaClass();
        }
        if ((o instanceof JSJavaArray)) {
          return ((JSJavaArray)o).getJSJavaClass();
        }
        return UNDEFINED;
      }
      if ((o instanceof String))
      {
        InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass((String)o);
        return getJSJavaFactory().newJSJavaKlass(ik).getJSJavaClass();
      }
      return UNDEFINED;
    }
    return UNDEFINED;
  }
  
  public Object dumpClass(Object[] args)
  {
    if (args.length == 0) {
      return Boolean.FALSE;
    }
    Object clazz = args[0];
    if (clazz == null) {
      return Boolean.FALSE;
    }
    InstanceKlass ik = null;
    if ((clazz instanceof String))
    {
      String name = (String)clazz;
      if (name.startsWith("0x"))
      {
        VM vm = VM.getVM();
        Address addr = vm.getDebugger().parseAddress(name);
        Oop oop = vm.getObjectHeap().newOop(addr.addOffsetToAsOopHandle(0L));
        if ((oop instanceof InstanceKlass)) {
          ik = (InstanceKlass)oop;
        } else {
          return Boolean.FALSE;
        }
      }
      else
      {
        ik = SystemDictionaryHelper.findInstanceKlass((String)clazz);
      }
    }
    else if ((clazz instanceof JSJavaClass))
    {
      JSJavaKlass jk = ((JSJavaClass)clazz).getJSJavaKlass();
      if ((jk != null) && ((jk instanceof JSJavaInstanceKlass))) {
        ik = ((JSJavaInstanceKlass)jk).getInstanceKlass();
      }
    }
    else
    {
      return Boolean.FALSE;
    }
    if (ik == null) {
      return Boolean.FALSE;
    }
    StringBuffer buf = new 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd