sa-jdi

gnature;
  
  VM saVM()
  {
    return saVM;
  }
  
  SystemDictionary saSystemDictionary()
  {
    return saSystemDictionary;
  }
  
  SymbolTable saSymbolTable()
  {
    return saSymbolTable;
  }
  
  Universe saUniverse()
  {
    return saUniverse;
  }
  
  ObjectHeap saObjectHeap()
  {
    return saObjectHeap;
  }
  
  private boolean retrievedAllTypes = false;
  private List bootstrapClasses;
  private ArrayList allThreads;
  private ArrayList topLevelGroups;
  final int sequenceNumber;
  private final Map objectsByID = new HashMap();
  private final ReferenceQueue referenceQueue = new ReferenceQueue();
  private Symbol javaLangString;
  private Symbol javaLangThread;
  private Symbol javaLangThreadGroup;
  private Symbol javaLangClass;
  private Symbol javaLangClassLoader;
  private Symbol javaLangThrowable;
  private Symbol javaLangObject;
  private Symbol javaLangCloneable;
  private Symbol javaIoSerializable;
  private Symbol javaLangEnum;
  private String defaultStratum;
  
  Symbol javaLangObject()
  {
    return javaLangObject;
  }
  
  Symbol javaLangCloneable()
  {
    return javaLangCloneable;
  }
  
  Symbol javaIoSerializable()
  {
    return javaIoSerializable;
  }
  
  Symbol javaLangEnum()
  {
    return javaLangEnum;
  }
  
  Symbol javaLangThrowable()
  {
    return javaLangThrowable;
  }
  
  private void initClassNameSymbols()
  {
    SymbolTable st = saSymbolTable();
    javaLangString = st.probe("java/lang/String");
    javaLangThread = st.probe("java/lang/Thread");
    javaLangThreadGroup = st.probe("java/lang/ThreadGroup");
    javaLangClass = st.probe("java/lang/Class");
    javaLangClassLoader = st.probe("java/lang/ClassLoader");
    javaLangThrowable = st.probe("java/lang/Throwable");
    javaLangObject = st.probe("java/lang/Object");
    javaLangCloneable = st.probe("java/lang/Cloneable");
    javaIoSerializable = st.probe("java/io/Serializable");
    javaLangEnum = st.probe("java/lang/Enum");
  }
  
  private void init()
  {
    saVM = VM.getVM();
    saUniverse = saVM.getUniverse();
    saSystemDictionary = saVM.getSystemDictionary();
    saSymbolTable = saVM.getSymbolTable();
    saObjectHeap = saVM.getObjectHeap();
    initClassNameSymbols();
  }
  
  public static VirtualMachineImpl createVirtualMachineForCorefile(VirtualMachineManager mgr, String javaExecutableName, String coreFileName, int sequenceNumber)
    throws Exception
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(coreFileName != null, "SA VirtualMachineImpl: core filename = null is not yet implemented");
    }
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(javaExecutableName != null, "SA VirtualMachineImpl: java executable = null is not yet implemented");
    }
    VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
    try
    {
      saAgent.attach(javaExecutableName, coreFileName);
      myvm.init();
    }
    catch (Exception ee)
    {
      saAgent.detach();
      throw ee;
    }
    return myvm;
  }
  
  public static VirtualMachineImpl createVirtualMachineForPID(VirtualMachineManager mgr, int pid, int sequenceNumber)
    throws Exception
  {
    VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
    try
    {
      saAgent.attach(pid);
      myvm.init();
    }
    catch (Exception ee)
    {
      saAgent.detach();
      throw ee;
    }
    return myvm;
  }
  
  public static VirtualMachineImpl createVirtualMachineForServer(VirtualMachineManager mgr, String server, int sequenceNumber)
    throws Exception
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(server != null, "SA VirtualMachineImpl: DebugServer = null is not yet implemented");
    }
    VirtualMachineImpl myvm = new VirtualMachineImpl(mgr, sequenceNumber);
    try
    {
      saAgent.attach(server);
      myvm.init();
    }
    catch (Exception ee)
    {
      saAgent.detach();
      throw ee;
    }
    return myvm;
  }
  
  VirtualMachineImpl(VirtualMachineManager mgr, int sequenceNumber)
    throws Exception
  {
    super(null);
    vm = this;
    
    this.sequenceNumber = sequenceNumber;
    vmmgr = mgr;
    
    threadGroupForJDI = new ThreadGroup("JDI [" + hashCode() + "]");
    
    ((VirtualMachineManagerImpl)mgr).addVirtualMachine(this);
    
    System.setProperty("sun.jvm.hotspot.debugger.useProcDebugger", "true");
    System.setProperty("sun.jvm.hotspot.debugger.useWindbgDebugger", "true");
  }
  
  private static Class vmCannotBeModifiedExceptionClass = null;
  private Observer disposeObserver;
  
  void throwNotReadOnlyException(String operation)
  {
    RuntimeException re = null;
    if (vmCannotBeModifiedExceptionClass == null) {
      try
      {
        vmCannotBeModifiedExceptionClass = Class.forName("com.sun.jdi.VMCannotBeModifiedException");
      }
      catch (ClassNotFoundException cnfe)
      {
        vmCannotBeModifiedExceptionClass = UnsupportedOperationException.class;
      }
    }
    try
    {
      re = (RuntimeException)vmCannotBeModifiedExceptionClass.newInstance();
    }
    catch (Exception exp)
    {
      re = new RuntimeException(exp.getMessage());
    }
    throw re;
  }
  
  public boolean equals(Object obj)
  {
    return this == obj;
  }
  
  public int hashCode()
  {
    return System.identityHashCode(this);
  }
  
  public List classesByName(String className)
  {
    String signature = JNITypeParser.typeNameToSignature(className);
    if (!retrievedAllTypes) {
      retrieveAllClasses();
    }
    List list = findReferenceTypes(signature);
    return Collections.unmodifiableList(list);
  }
  
  public List allClasses()
  {
    if (!retrievedAllTypes) {
      retrieveAllClasses();
    }
    ArrayList a;
    synchronized (this)
    {
      a = new ArrayList(typesBySignature);
    }
    return Collections.unmodifiableList(a);
  }
  
  List bootstrapClasses()
  {
    Iterator itr;
    if (bootstrapClasses == null)
    {
      bootstrapClasses = new ArrayList();
      List all = allClasses();
      for (itr = all.iterator(); itr.hasNext();)
      {
        ReferenceType type = (ReferenceType)itr.next();
        if (type.classLoader() == null) {
          bootstrapClasses.add(type);
        }
      }
    }
    return bootstrapClasses;
  }
  
  private synchronized List findReferenceTypes(String signature)
  {
    if (typesByID == null) {
      return new ArrayList(0);
    }
    String typeName = null;
    if (signature.charAt(0) == 'L') {
      typeName = signature.substring(1, signature.length() - 1);
    } else {
      typeName = signature;
    }
    Symbol typeNameSym = saSymbolTable().probe(typeName);
    if (typeNameSym == null) {
      return new ArrayList(0);
    }
    Iterator iter = typesBySignature.iterator();
    List list = new ArrayList();
    while (iter.hasNext())
    {
      ReferenceTypeImpl type = (ReferenceTypeImpl)iter.next();
      if (typeNameSym.equals(type.typeNameAsSymbol())) {
        list.add(type);
      }
    }
    return list;
  }
  
  private void retrieveAllClasses()
  {
    final List saKlasses = new ArrayList();
    SystemDictionary.ClassVisitor visitor = new SystemDictionary.ClassVisitor()
    {
      public void visit(Klass k)
      {
        for (Klass l = k; l != null; l = l.arrayKlassOrNull()) {
          if ((l instanceof ArrayKlass))
          {
            saKlasses.add(l);
          }
          else
          {
            int status = l.getClassStatus();
            if ((status & 0x2) != 0) {
              saKlasses.add(l);
            }
          }
        }
      }
    };
    saSystemDictionary.classesDo(visitor);
    
    saVM.getUniverse().basicTypeClassesDo(visitor);
    synchronized (this)
    {
      if (!retrievedAllTypes)
      {
        int count = saKlasses.size();
        ReferenceTypeImpl type;
        for (int ii = 0; ii < count; ii++)
        {
          Klass kk = (Klass)saKlasses.get(ii);
          type = referenceType(kk);
        }
        retrievedAllTypes = true;
      }
    }
  }
  
  ReferenceTypeImpl referenceType(Klass kk)
  {
    ReferenceTypeImpl retType = null;
    synchronized (this)
    {
      if (typesByID != null) {
        retType = (ReferenceTypeImpl)typesByID.get(kk);
      }
      if (retType == null) {
        retType = addReferenceType(kk);
      }
    }
    return retType;
  }
  
  private void initReferenceTypes()
  {
    typesByID = new HashMap();
    typesBySignature = new ArrayList();
  }
  
  private synchronized ReferenceTypeImpl addReferenceType(Klass kk)
  {
    if (typesByID == null) {
      initReferenceTypes();
    }
    ReferenceTypeImpl newRefType = null;
    if (((kk instanceof ObjArrayKlass)) || ((kk instanceof TypeArrayKlass))) {
      newRefType = new ArrayTypeImpl(this, (ArrayKlass)kk);
    } else if ((kk instanceof InstanceKlass))
    {
      if (kk.isInterface()) {
        newRefType = new InterfaceTypeImpl(this, (InstanceKlass)kk);
      } else {
        newRefType = new ClassTypeImpl(this, (InstanceKlass)kk);
      }
    }
    else {
      throw new RuntimeException("should not reach here");
    }
    typesByID.put(kk, newRefType);
    typesBySignature.add(newRefType);
    return newRefType;
  }
  
  ThreadGroup threadGroupForJDI()
  {
    return threadGroupForJDI;
  }
  
  public void redefineClasses(Map classToBytes)
  {
    throwNotReadOnlyException("VirtualMachineImpl.redefineClasses()");
  }
  
  private List getAllThreads()
  {
    if (allThreads == null)
    {
      allThreads = new ArrayList(10);
      for (JavaThread thread = saVM.getThreads().first(); thread != null; thread = thread.next()) {
        if (!thread.isHiddenFromExternalView())
        {
          ThreadReferenceImpl myThread = threadMirror(thread);
          allThreads.add(myThread);
        }
      }
    }
    return allThreads;
  }
  
  public List allThreads()
  {
    return Collections.unmodifiableList(getAllThreads());
  }
  
  public void suspend()
  {
    throwNotReadOnlyException("VirtualMachineImpl.suspend()");
  }
  
  public void resume()
  {
    throwNotReadOnlyException("VirtualMachineImpl.resume()");
  }
  
  public List topLevelThreadGroups()
  {
    if (topLevelGroups == null)
    {
      topLevelGroups = new ArrayList(1);
      Iterator myIt = getAllThreads().iterator();
      while (myIt.hasNext())
      {
        ThreadReferenceImpl myThread = (ThreadReferenceImpl)myIt.next();
        ThreadGroupReference myGroup = myThread.threadGroup();
        ThreadGroupReference myParent = myGroup.parent();
        if (myGroup.parent() == null)
        {
          topLevelGroups.add(myGroup);
          break;
        }
      }
    }
    return Collections.unmodifiableList(topLevelGroups);
  }
  
  public EventQueue eventQueue()
  {
    throwNotReadOnlyException("VirtualMachine.eventQueue()");
    return null;
  }
  
  public EventRequestManager eventRequestManager()
  {
    throwNotReadOnlyException("VirtualMachineImpl.eventRequestManager()");
    return null;
  }
  
  public BooleanValue mirrorOf(boolean value)
  {
    return new BooleanValueImpl(this, value);
  }
  
  public ByteValue mirrorOf(byte value)
  {
    return new ByteValueImpl(this, value);
  }
  
  public CharValue mirrorOf(char value)
  {
    return new CharValueImpl(this, value);
  }
  
  public ShortValue mirrorOf(short value)
  {
    return new ShortValueImpl(this, value);
  }
  
  public IntegerValue mirrorOf(int value)
  {
    return new IntegerValueImpl(this, value);
  }
  
  public LongValue mirrorOf(long value)
  {
    return new LongValueImpl(this, value);
  }
  
  public FloatValue mirrorOf(float value)
  {
    return new FloatValueImpl(this, value);
  }
  
  public DoubleValue mirrorOf(double value)
  {
    return new DoubleValueImpl(this, value);
  }
  
  public StringReference mirrorOf(String value)
  {
    throwNotReadOnlyException("VirtualMachinestop.mirrorOf(String)");
    return null;
  }
  
  public VoidValue mirrorOfVoid()
  {
    if (voidVal == null) {
      voidVal = new VoidValueImpl(this);
    }
    return voidVal;
  }
  
  public Process process()
  {
    throwNotReadOnlyException("VirtualMachine.process");
    return null;
  }
  
  void setDisposeObserver(Observer observer)
  {
    disposeObserver = observer;
  }
  
  private void notifyDispose()
  {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(disposeObserver != null, "null VM.dispose observer");
    }
    disposeObserver.update(null, null);
  }
  
  public void dispose()
  {
    saAgent.detach();
    notifyDispose();
  }
  
  public void exit(int exitCode)
  {
    throwNotReadOnlyException("VirtualMachine.exit(int)");
  }
  
  public boolean canBeModified()
  {
    return false;
  }
  
  public boolean canWatchFieldModification()
  {
    return false;
  }
  
  public boolean canWatchFieldAccess()
  {
    return false;
  }
  
  public boolean canGetBytecodes()
  {
    return true;
  }
  
  public boolean canGetSyntheticAttribute()
  {
    return true;
  }
  
  public boolean canGetOwnedMonitorInfo()
  {
    return false;
  }
  
  public boolean canGetCurrentContendedMonitor()
  {
    return false;
  }
  
  public boolean canGetMonitorInfo()
  {
    return false;
  }
  
  public boolean canGet1_5LanguageFeatures()
  {
    return true;
  }
  
  public boolean canUseInstanceFilters()
  {
    return false;
  }
  
  public boolean canRedefineClasses()
  {
    return false;
  }
  
  public boolean canAddMethod()
  {
    return false;
  }
  
  public boolean canUnrestrictedlyRedefineClasses()
  {
    return false;
  }
  
  public boolean canPopFrames()
  {
    return false;
  }
  
  public boolean canGetSourceDebugExtension()
  {
    return false;
  }
  
  public boolean canRequestVMDeathEvent()
  {
    return false;
  }
  
  public boolean canForceEarlyReturn()
  {
    return false;
  }
  
  public boolean canGetConstantPool()
  {
    return true;
  }
  
  public boolean canGetClassFileVersion()
  {
    return true;
  }
  
  public boolean canGetMethodReturnValues()
  {
    return false;
  }
  
  public boolean canGetInstanceInfo()
  {
    return true;
  }
  
  public boolean canUseSourceNameFilters()
  {
    return false;
  }
  
  public boolean canRequestMonitorEvents()
  {
    return false;
  }
  
  public boolean canGetMonitorFrameInfo()
  {
    return true;
  }
  
  public long[] instanceCounts(List classes)
  {
    if (!canGetInstanceInfo()) {
      throw new UnsupportedOperationException("target does not support getting instances");
    }
    final long[] retValue = new long[classes.size()];
    
    final Klass[] klassArray = new Klass[classes.size()];
    
    boolean allAbstractClasses = true;
    for (int i = 0; i < classes.size(); i++)
    {
      ReferenceTypeImpl rti = (ReferenceTypeImpl)classes.get(i);
      klassArray[i] = rti.ref();
      retValue[i] = 0L;
      if ((!rti.isAbstract()) && (!(rti instanceof InterfaceType))) {
        allAbstractClasses = false;
      }
    }
    if (allAbstractClasses) {
      return retValue;
    }
    final int size = classes.size();
    saObjectHeap.iterate(new DefaultHeapVisitor()
    {
      public boolean doObj(Oop oop)
      {
        for (int i = 0; i < size; i++) {
          if (klassArray[i].equals(oop.getKlass()))
          {
            retValue[i] += 1L;
            break;
          }
        }
        return false;
      }
    });
    return retValue;
  }
  
  private List getPath(String pathName)
  {
    String cp = saVM.getSystemProperty(pathName);
    String pathSep = saVM.getSystemProperty("path.separator");
    ArrayList al = new ArrayList();
    StringTokenizer st = new StringTokenizer(cp, pathSep);
    while (st.hasMoreTokens()) {
      al.add(st.nextToken());
    }
    al.trimToSize();
    return al;
  }
  
  public List classPath()
  {
    return getPath("java.class.path");
  }
  
  public List bootClassPath()
  {
    return getPath("sun.boot.class.path");
  }
  
  public String baseDirectory()
  {
    return saVM.getSystemProperty("user.dir");
  }
  
  public void setDefaultStratum(String stratum)
  {
    defaultStratum = stratum;
  }
  
  public String getDefaultStratum()
  {
    return defaultStratum;
  }
  
  public String description()
  {
    String[] versionParts = { "" + vmmgr.majorInterfaceVersion(), "" + vmmgr.minorInterfaceVersion(), name() };
    
    return MessageFormat.format(ResourceBundle.getBundle("com.sun.tools.jdi.resources.jdi").getString("version_format"), versionParts);
  }
  
  public String version()
  {
    return saVM.getSystemProperty("java.version");
  }
  
  public String name()
  {
    StringBuffer sb = new StringBuffer();
    sb.append("JVM version ");
    sb.append(version());
    sb.append(" (");
    sb.append(saVM.getSystemProperty("java.vm.name"));
    sb.append(", ");
    sb.append(saVM.getSystemProperty("java.vm.info"));
    sb.append(")");
    return sb.toString();
  }
  
  public VirtualMachine virtualMachine()
  {
    return this;
  }
  
  public String toString()
  {
    return name();
  }
  
  public void setDebugTraceMode(int traceFlags) {}
  
  public boolean canWalkHeap()
  {
    return true;
  }
  
  public List allObjects()
  {
    final List objects = new ArrayList(0);
    saObjectHeap.iterate(new DefaultHeapVisitor()
    {
      public boolean doObj(Oop oop)
      {
        objects.add(objectMirror(oop));
        return false;
      }
    });
    return objects;
  }
  
  public List objectsByType(ReferenceType type)
  {
    return objectsByType(type, true);
  }
  
  private List objectsByExactType(ReferenceType type)
  {
    final List objects = new ArrayList(0);
    final Klass givenKls = ((ReferenceTypeImpl)type).ref();
    saObjectHeap.iterate(new DefaultHeapVisitor()
    {
      public boolean doObj(Oop oop)
      {
        if (givenKls.equals(oop.getKlass())) {
          objects.add(objectMirror(oop));
        }
        return false;
      }
    });
    return objects;
  }
  
  private List objectsBySubType(ReferenceType type)
  {
    final List objects = new ArrayList(0);
    final ReferenceType givenType = type;
    saObjectHeap.iterate(new DefaultHeapVisitor()
    {
      public boolean doObj(Oop oop)
      {
        ReferenceTypeImpl curType = referenceType(oop.getKlass());
        if (curType.isAssignableTo(givenType)) {
          objects.add(objectMirror(oop));
        }
        return false;
      }
    });
    return objects;
  }
  
  public List objectsByType(ReferenceType type, boolean includeSubtypes)
  {
    Klass kls = ((ReferenceTypeImpl)type).ref();
    if ((kls instanceof InstanceKlass))
    {
      InstanceKlass ik = (InstanceKlass)kls;
      if (ik.isInterface())
      {
        if (ik.nofImplementors() == 0L) {
          return new ArrayList(0);
        }
      }
      else if ((ik.getAccessFlagsObj().isFinal()) || (ik.getSubklassKlass() == null)) {
        includeSubtypes = false;
      }
    }
    else
    {
      ArrayTypeImpl arrayType = (ArrayTypeImpl)type;
      try
      {
        Type componentType = arrayType.componentType();
        if ((componentType instanceof PrimitiveType)) {
          includeSubtypes = false;
        }
      }
      catch (ClassNotLoadedException cnle) {}
    }
    if (includeSubtypes) {
      return objectsBySubType(type);
    }
    return objectsByExactType(type);
  }
  
  Type findBootType(String signature)
    throws ClassNotLoadedException
  {
    List types = allClasses();
    Iterator iter = types.iterator();
    while (iter.hasNext())
    {
      ReferenceType type = (ReferenceType)iter.next();
      if ((type.classLoader() == null) && (type.signature().equals(signature))) {
        return type;
      }
    }
    JNITypeParser parser = new JNITypeParser(signature);
    throw new ClassNotLoadedException(parser.typeName(), "Type " + parser.typeName() + " not loaded");
  }
  
  BooleanType theBooleanType()
  {
    if (theBooleanType == null) {
      synchronized (this)
      {
        if (theBooleanType == null) {
          theBooleanType = new BooleanTypeImpl(this);
        }
      }
    }
    return theBooleanType;
  }
  
  ByteType theByteType()
  {
    if (theByteType == null) {
      synchronized (this)
      {
        if (theByteType == null) {
          theByteType = new ByteTypeImpl(this);
        }
      }
    }
    return theByteType;
  }
  
  CharType theCharType()
  {
    if (theCharType == null) {
      synchronized (this)
      {
        if (theCharType == null) {
          theCharType = new CharTypeImpl(this);
        }
      }
    }
    return theCharType;
  }
  
  ShortType theShortType()
  {
    if (theShortType == null) {
      synchronized (this)
      {
        if (theShortType == null) {
          theShortType = new ShortTypeImpl(this);
        }
      }
    }
    return theShortType;
  }
  
  IntegerType theIntegerType()
  {
    if (theIntegerType == null) {
      synchronized (this)
      {
        if (theIntegerType == null) {
          theIntegerType = new IntegerTypeImpl(this);
        }
      }
    }
    return theIntegerType;
  }
  
  LongType theLongType()
  {
    if (theLongType == null) {
      synchronized (this)
      {
        if (theLongType == null) {
          theLongType = new LongTypeImpl(this);
        }
      }
    }
    return theLongType;
  }
  
  FloatType theFloatType()
  {
    if (theFloatType == null) {
      synchronized (this)
      {
        if (theFloatType == null) {
          theFloatType = new FloatTypeImpl(this);
        }
      }
    }
    return theFloatType;
  }
  
  DoubleType theDoubleType()
  {
    if (theDoubleType == null) {
      synchronized (this)
      {
        if (theDoubleType == null) {
          theDoubleType = new DoubleTypeImpl(this);
        }
      }
    }
    return theDoubleType;
  }
  
  VoidType theVoidType()
  {
    if (theVoidType == null) {
      synchronized (this)
      {
        if (theVoidType == null) {
          theVoidType = new VoidTypeImpl(this);
        }
      }
    }
    return theVoidType;
  }
  
  PrimitiveType primitiveTypeMirror(char tag)
  {
    switch (tag)
    {
    case 'Z': 
      return theBooleanType();
    case 'B': 
      return theByteType();
    case 'C': 
      return theCharType();
    case 'S': 
      return theShortType();
    case 'I': 
      return theIntegerType();
    case 'J': 
      return theLongType();
    case 'F': 
      return theFloatType();
    case 'D': 
      return theDoubleType();
    }
    throw new IllegalArgumentException("Unrecognized primitive tag " + tag);
  }
  
  private void processQueue()
  {
    Reference ref;
    while ((ref = referenceQueue.poll()) != null)
    {
      SoftObjectReference softRef = (SoftObjectReference)ref;
      removeObjectMirror(softRef);
    }
  }
  
  long getAddressValue(Oop obj)
  {
    return vm.saVM.getDebugger().getAddressValue(obj.getHandle());
  }
  
  synchronized ObjectReferenceImpl objectMirror(Oop key)
  {
    processQueue();
    if (key == null) {
      return null;
    }
    ObjectReferenceImpl object = null;
    
    SoftObjectReference ref = (SoftObjectReference)objectsByID.get(key);
    if (ref != null) {
      object = ref.object();
    }
    if (object == null)
    {
      if ((key instanceof Instance))
      {
        Symbol className = key.getKlass().getName();
        if (Assert.ASSERTS_ENABLED) {
          Assert.that(className != null, "Null class name");
        }
        Instance inst = (Instance)key;
        if (className.equals(javaLangString))
        {
          object = new StringReferenceImpl(this, inst);
        }
        else if (className.equals(javaLangThread))
        {
          object = new ThreadReferenceImpl(this, inst);
        }
        else if (className.equals(javaLangThreadGroup))
        {
          object = new ThreadGroupReferenceImpl(this, inst);
        }
        else if (className.equals(javaLangClass))
        {
          object = new ClassObjectReferenceImpl(this, inst);
        }
        else if (className.equals(javaLangClassLoader))
        {
          object = new ClassLoaderReferenceImpl(this, inst);
        }
        else
        {
          Klass kls = key.getKlass().getSuper();
          while (kls != null)
          {
            className = kls.getName();
            if (className.equals(javaLangThread))
            {
              object = new ThreadReferenceImpl(this, inst);
              break;
            }
            if (className.equals(javaLangThreadGroup))
            {
              object = new ThreadGroupReferenceImpl(this, inst);
              break;
            }
            if (className.equals(javaLangClassLoader))
            {
              object = new ClassLoaderReferenceImpl(this, inst);
              break;
            }
            kls = kls.getSuper();
          }
          if (object == null) {
            object = new ObjectReferenceImpl(this, inst);
          }
        }
      }
      else if ((key instanceof TypeArray))
      {
        object = new ArrayReferenceImpl(this, (Array)key);
      }
      else if ((key instanceof ObjArray))
      {
        object = new ArrayReferenceImpl(this, (Array)key);
      }
      else
      {
        throw new RuntimeException("unexpected object type " + key);
      }
      ref = new SoftObjectReference(key, object, referenceQueue);
      
      objectsByID.put(key, ref);
    }
    else
    {
      ref.incrementCount();
    }
    return object;
  }
  
  synchronized void removeObjectMirror(SoftObjectReference ref)
  {
    objectsByID.remove(ref.key());
  }
  
  StringReferenceImpl stringMirror(Instance id)
  {
    return (StringReferenceImpl)objectMirror(id);
  }
  
  ArrayReferenceImpl arrayMirror(Array id)
  {
    return (ArrayReferenceImpl)objectMirror(id);
  }
  
  ThreadReferenceImpl threadMirror(Instance id)
  {
    return (ThreadReferenceImpl)objectMirror(id);
  }
  
  ThreadReferenceImpl threadMirror(JavaThread jt)
  {
    return (ThreadReferenceImpl)objectMirror(jt.getThreadObj());
  }
  
  ThreadGroupReferenceImpl threadGroupMirror(Instance id)
  {
    return (ThreadGroupReferenceImpl)objectMirror(id);
  }
  
  ClassLoaderReferenceImpl classLoaderMirror(Instance id)
  {
    return (ClassLoaderReferenceImpl)objectMirror(id);
  }
  
  ClassObjectReferenceImpl classObjectMirror(Instance id)
  {
    return (ClassObjectReferenceImpl)objectMirror(id);
  }
  
  private static class SoftObjectReference
    extends SoftReference
  {
    int count;
    Object key;
    
    SoftObjectReference(Object key, ObjectReferenceImpl mirror, ReferenceQueue queue)
    {
      super(queue);
      count = 1;
      this.key = key;
    }
    
    int count()
    {
      return count;
    }
    
    void incrementCount()
    {
      count += 1;
    }
    
    Object key()
    {
      return key;
    }
    
    ObjectReferenceImpl object()
    {
      return (ObjectReferenceImpl)get();
    }
  }
}

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

import sun.jvm.hotspot.runtime.ClassConstants;

public abstract interface VMModifiers
  extends ClassConstants
{
  public static final int PUBLIC = 1;
  public static final int PRIVATE = 2;
  public static final int PROTECTED = 4;
  public static final int STATIC = 8;
  public static final int FINAL = 16;
  public static final int SYNCHRONIZED = 32;
  public static final int VOLATILE = 64;
  public static final int BRIDGE = 64;
  public static final int TRANSIENT = 128;
  public static final int VARARGS = 128;
  public static final int IS_ENUM_CONSTANT = 16384;
  public static final int NATIVE = 256;
  public static final int INTERFACE = 512;
  public static final int ABSTRACT = 1024;
  public static final int SYNTHETIC = 4096;
}

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

import com.sun.jdi.VirtualMachine;
import com.sun.jdi.VoidType;

public class VoidTypeImpl
  extends TypeImpl
  implements VoidType
{
  VoidTypeImpl(VirtualMachine vm)
  {
    super(vm);
  }
  
  public String signature()
  {
    return "V";
  }
  
  public String toString()
  {
    return name();
  }
}

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

import com.sun.jdi.InvalidTypeException;
import com.sun.jdi.Type;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.VoidValue;

public class VoidValueImpl
  extends ValueImpl
  implements VoidValue
{
  VoidValueImpl(VirtualMachine aVm)
  {
    super(aVm);
  }
  
  public boolean equals(Object obj)
  {
    return (obj != null) && ((obj instanceof VoidValue)) && (super.equals(obj));
  }
  
  public int hashCode()
  {
    return type().hashCode();
  }
  
  public Type type()
  {
    return vm.theVoidType();
  }
  
  ValueImpl prepareForAssignmentTo(ValueContainer destination)
    throws InvalidTypeException
  {
    throw new InvalidTypeException();
  }
  
  public String toString()
  {
    return "<void value>";
  }
}

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

import sun.jvm.hotspot.debugger.SymbolLookup;
import sun.jvm.hotspot.types.Type;
import sun.jvm.hotspot.types.basic.BasicVtblAccess;

public class LinuxVtblAccess
  extends BasicVtblAccess
{
  private String vt;
  
  public LinuxVtblAccess(SymbolLookup symbolLookup, String[] dllNames)
  {
    super(symbolLookup, dllNames);
    if ((symbolLookup.lookup("libjvm.so", "__vt_10JavaThread") != null) || (symbolLookup.lookup("libjvm_g.so", "__vt_10JavaThread") != null)) {
      vt = "__vt_";
    } else {
      vt = "_ZTV";
    }
  }
  
  protected String vtblSymbolForType(Type type)
  {
    return vt + type.getName().length() + type;
  }
}

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

import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.runtime.JNIid;

public class BreakpointEvent
  extends Event
{
  private Oop thread;
  private Oop clazz;
  private JNIid method;
  private int location;
  
  public BreakpointEvent(Oop thread, Oop clazz, JNIid method, int location)
  {
    super(Event.Type.BREAKPOINT);
    this.thread = thread;
    this.clazz = clazz;
    this.method = method;
    this.location = location;
  }
  
  public Oop thread()
  {
    return thread;
  }
  
  public Oop clazz()
  {
    return clazz;
  }
  
  public JNIid methodID()
  {
    return method;
  }
  
  public int location()
  {
    return location;
  }
}

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

import sun.jvm.hotspot.debugger.Address;

class CIntegerAccessor
{
  private Address addr;
  private long numBytes;
  private boolean isUnsigned;
  
  CIntegerAccessor(Address addr, long numBytes, boolean isUnsigned)
  {
    this.addr = addr;
    this.numBytes = numBytes;
    this.isUnsigned = isUnsigned;
  }
  
  long getValue()
  {
    return addr.getCIntegerAt(0L, numBytes, isUnsigned);
  }
  
  void setValue(long value)
  {
    addr.setCIntegerAt(0L, numBytes, value);
  }
}

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

import java.io.UnsupportedEncodingException;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.DebuggerException;

class CStringAccessor
{
  private Address addr;
  private int bufLen;
  
  CStringAccessor(Address addr, int bufLen)
  {
    this.addr = addr;
    this.bufLen = bufLen;
  }
  
  String getValue()
    throws DebuggerException
  {
    int len = 0;
    while ((addr.getCIntegerAt(len, 1L, true) != 0L) && (len < bufLen)) {
      len++;
    }
    byte[] res = new byte[len];
    for (int i = 0; i < len; i++) {
      res[i] = ((byte)(int)addr.getCIntegerAt(i, 1L, true));
    }
    try
    {
      return new String(res, "US-ASCII");
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DebuggerException("Unable to use US-ASCII encoding");
    }
  }
  
  void setValue(String value)
    throws DebuggerException
  {
    try
    {
      byte[] data = value.getBytes("US-ASCII");
      if (data.length >= bufLen) {
        throw new DebuggerException("String too long");
      }
      for (int i = 0; i < data.length; i++) {
        addr.setCIntegerAt(i, 1L, data[i]);
      }
      addr.setCIntegerAt(data.length, 1L, 0L);
    }
    catch (UnsupportedEncodingException e)
    {
      throw new DebuggerException("Unable to use US-ASCII encoding");
    }
  }
}

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

public class Event$Type
{
  public static final Type BREAKPOINT = new Type();
  public static final Type EXCEPTION = new Type();
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.livejvm.Event.Type
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.livejvm;

public class Event
{
  private Type type;
  
  public static class Type
  {
    public static final Type BREAKPOINT = new Type();
    public static final Type EXCEPTION = new Type();
  }
  
  public Event(Type type)
  {
    this.type = type;
  }
  
  public Type getType()
  {
    return type;
  }
}

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

import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.runtime.JNIid;

public class ExceptionEvent
  extends Event
{
  private Oop thread;
  private Oop clazz;
  private JNIid method;
  private int location;
  private Oop exception;
  private Oop catchClass;
  private JNIid catchMethod;
  private int catchLocation;
  
  public ExceptionEvent(Oop thread, Oop clazz, JNIid method, int location, Oop exception, Oop catchClass, JNIid catchMethod, int catchLocation)
  {
    super(Event.Type.EXCEPTION);
    this.thread = thread;
    this.clazz = clazz;
    this.method = method;
    this.location = location;
    this.exception = exception;
    this.catchClass = catchClass;
    this.catchMethod = catchMethod;
    this.catchLocation = catchLocation;
  }
  
  public Oop thread()
  {
    return thread;
  }
  
  public Oop clazz()
  {
    return clazz;
  }
  
  public JNIid methodID()
  {
    return method;
  }
  
  public int location()
  {
    return location;
  }
  
  public Oop exception()
  {
    return exception;
  }
  
  public Oop catchClass()
  {
    return catchClass;
  }
  
  public JNIid catchMethodID()
  {
    return catchMethod;
  }
  
  public int catchLocation()
  {
    return catchLocation;
  }
}

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

import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.oops.ObjectHeap;
import sun.jvm.hotspot.oops.Oop;
import sun.jvm.hotspot.utilities.Assert;

class JNIHandleAccessor
{
  private Address addr;
  private ObjectHeap heap;
  
  JNIHandleAccessor(Address addr, ObjectHeap heap)
  {
    this.addr = addr;
    this.heap = heap;
  }
  
  Oop getValue()
  {
    Address handle = addr.getAddressAt(0L);
    if (handle == null) {
      return null;
    }
    return heap.newOop(handle.getOopHandleAt(0L));
  }
  
  void setValue(Oop value)
  {
    Address handle = addr.getAddressAt(0L);
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(handle != null, "Must have valid global JNI handle for setting");
    }
    handle.setOopHandleAt(0L, value.getHandle());
  }
}

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

public class ServiceabilityAgentJVMDIModule$BreakpointToggleResult
{
  private boolean success;
  private String errMsg;
  private int lineNumber;
  private int bci;
  private boolean wasSet;
  private String methodName;
  private String methodSig;
  
  public ServiceabilityAgentJVMDIModule$BreakpointToggleResult(int lineNumber, int bci, boolean wasSet, String methodName, String methodSig)
  {
    this.lineNumber = lineNumber;
    this.bci = bci;
    this.wasSet = wasSet;
    this.methodName = methodName;
    this.methodSig = methodSig;
    success = true;
  }
  
  public ServiceabilityAgentJVMDIModule$BreakpointToggleResult(String errMsg)
  {
    this.errMsg = errMsg;
    success = false;
  }
  
  public boolean getSuccess()
  {
    return success;
  }
  
  public String getErrMsg()
  {
    return errMsg;
  }
  
  public int getLineNumber()
  {
    return lineNumber;
  }
  
  public int getBCI()
  {
    return bci;
  }
  
  public boolean getWasSet()
  {
    return wasSet;
  }
  
  public String getMethodName()
  {
    return methodName;
  }
  
  public String getMethodSignature()
  {
    return methodSig;
  }
}

/* Location:
 * Qualified Name:     sun.jvm.hotspot.livejvm.ServiceabilityAgentJVMDIModule.BreakpointToggleResult
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package sun.jvm.hotspot.livejvm;

import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.debugger.Debugger;
import sun.jvm.hotspot.debugger.DebuggerException;
import sun.jvm.hotspot.runtime.JNIid;
import sun.jvm.hotspot.runtime.VM;

public class ServiceabilityAgentJVMDIModule
{
  private Debugger dbg;
  private String[] saLibNames;
  private String saLibName;
  private boolean attached;
  private boolean suspended;
  private static final int JVMDI_EVENT_BREAKPOINT = 2;
  private static final int JVMDI_EVENT_EXCEPTION = 4;
  private static long timeoutMillis = 3000L;
  private CIntegerAccessor saAttached;
  private CIntegerAccessor saEventPending;
  private CIntegerAccessor saEventKind;
  private JNIHandleAccessor saExceptionThread;
  private JNIHandleAccessor saExceptionClass;
  private JNIid saExceptionMethod;
  private CIntegerAccessor saExceptionLocation;
  private JNIHandleAccessor saExceptionException;
  private JNIHandleAccessor saExceptionCatchClass;
  private JNIid saExceptionCatchMethod;
  private CIntegerAccessor saExceptionCatchLocation;
  private JNIHandleAccessor saBreakpointThread;
  private JNIHandleAccessor saBreakpointClass;
  private JNIid saBreakpointMethod;
  private CIntegerAccessor saBreakpointLocation;
  private int SA_CMD_SUSPEND_ALL;
  private int SA_CMD_RESUME_ALL;
  private int SA_CMD_TOGGLE_BREAKPOINT;
  private int SA_CMD_BUF_SIZE;
  private CIntegerAccessor saCmdPending;
  private CIntegerAccessor saCmdType;
  private CIntegerAccessor saCmdResult;
  private CStringAccessor saCmdResultErrMsg;
  private CStringAccessor saCmdBkptSrcFileName;
  private CStringAccessor saCmdBkptPkgName;
  private CIntegerAccessor saCmdBkptLineNumber;
  private CIntegerAccessor saCmdBkptResWasError;
  private CIntegerAccessor saCmdBkptResLineNumber;
  private CIntegerAccessor saCmdBkptResBCI;
  private CIntegerAccessor saCmdBkptResWasSet;
  private CStringAccessor saCmdBkptResMethodName;
  private CStringAccessor saCmdBkptResMethodSig;
  
  public ServiceabilityAgentJVMDIModule(Debugger dbg, String[] saLibNames)
  {
    this.dbg = dbg;
    this.saLibNames = saLibNames;
  }
  
  public boolean canAttach()
  {
    return setupLookup("SA_CMD_SUSPEND_ALL");
  }
  
  public void attach()
    throws DebuggerException
  {
    if (!canAttach()) {
      throw new DebuggerException("Unable to initiate symbol lookup in SA's JVMDI module");
    }
    if (attached) {
      throw new DebuggerException("Already attached");
    }
    SA_CMD_SUSPEND_ALL = lookupConstInt("SA_CMD_SUSPEND_ALL");
    SA_CMD_RESUME_ALL = l
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