Package javax.tools.diagnostics.runtime.java

Examples of javax.tools.diagnostics.runtime.java.JavaClass


    if (object == null) {
      return null;
    }

    String className = null;
    JavaClass stringClass = null;

    try {
      stringClass = object.getJavaClass();
      className = stringClass.getName();
    } catch (CorruptDataException e) {
      e.printStackTrace();
      return null;
    }

    if (!className.equals("java/lang/String")) {
      throw new IllegalArgumentException(
          "Mismatched types - expecting java/lang/String, got `"
              + className + "'");
    }

    int offset = 0, count = 0;
    char[] value = null;
    JavaObject valueArray = null;
    boolean gotValue = false, gotOffset = false, gotCount = false;

    // Get all fields, pick out interesting ones.
    for (Object fobj : stringClass.getDeclaredFields()) {
     

      if (fobj instanceof CorruptData) {
        continue;
      }
View Full Code Here


  private boolean isInterface(long classID) throws CorruptDataException{
    //Use modifier
    if (classes == null){
      buildClasses();
    }
    JavaClass jClass = getClass(classID);
    if (jClass != null){
      if (Modifier.isInterface(jClass.getModifiers())){
        return true;
      }
    }
    return false;
  }
View Full Code Here

   */
  private JavaClass getClass(long classID){
    if (classes == null){
      classes = buildClasses();
    }
    JavaClass jcl = classes.get(classID);
    if (jcl == null){
      /**
       * Attemp to get directly, useful for system class loader which isn't covered
       * by build classes as it is not part of the class loader loaded classes.
       */
 
View Full Code Here

              Iterator frames = thd.getStackFrames().iterator();
              while(frames.hasNext()){
                JavaStackFrame jStackFrame = (JavaStackFrame)frames.next();
                JavaLocation jLocation = jStackFrame.getLocation();
                JavaMethod jMethod = jLocation.getMethod();
                JavaClass jClass = jMethod.getDeclaringClass();


                if (getMethodId(refType, jMethod) == methodID && jClass.getID().getAddress() == refType){
                  int line = -1;
                  try{
                    line = jLocation.getLineNumber();
                  }
                  catch(Exception exxy){}
View Full Code Here

              Iterator frames = thd.getStackFrames().iterator();
              while(frames.hasNext()){
                JavaStackFrame jStackFrame = (JavaStackFrame)frames.next();
                JavaLocation jLocation = jStackFrame.getLocation();
                JavaMethod jMethod = jLocation.getMethod();
                JavaClass jClass = jMethod.getDeclaringClass();


                if (getMethodId(refType, jMethod) == methodID && jClass.getID().getAddress() == refType){
                  int line = -1;
                  try{
                    line = jLocation.getLineNumber();
                  }
                  catch(Exception exxy){}
View Full Code Here

      }
      logr.log(JDILogger.LEVEL_VERBOSE, "ClassesBySignature(" + signature + ")"); //$NON-NLS-1$ //$NON-NLS-2$
      int count = 0;
      Iterator <JavaClass> javaClasses = classes.values().iterator();
      while (javaClasses.hasNext()){
        JavaClass javaClass = javaClasses.next();
        String searched = javaClass.getName();

        if (searched.equals(signature)){
          count++;
          if (javaClass.isArray()){
            vctr.add((byte)3);
          }else if (isInterface(javaClass.getID().getAddress())){
            vctr.add((byte)2);
          }else{
            vctr.add((byte)1);
          }
          //vctr.add((byte)1);
          addLongToVector(vctr, javaClass.getID().getAddress());
          //Verified Prepared and Initialized
          addIntToVector(vctr, 1 | 2 | 4);
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "Match: " + javaClass.getName() +" " + Long.toHexString(javaClass.getID().getAddress())); //$NON-NLS-1$
        }else{
          String mangledName = "" + searched + ""; //$NON-NLS-1$ //$NON-NLS-2$
          if (mangledName.equals(signature)){
            count++;
            if (javaClass.isArray()){
              vctr.add((byte)3);
            }else if (isInterface(javaClass.getID().getAddress())){
              vctr.add((byte)2);
            }else{
              vctr.add((byte)1);
            }
            //vctr.add((byte)1);
            addLongToVector(vctr, javaClass.getID().getAddress());
            //Verified Prepared and Initialized
            addIntToVector(vctr, 1 | 2 | 4);
            logr.log(JDILogger.LEVEL_VERYVERBOSE, "Mangled Match: " + javaClass.getName()); //$NON-NLS-1$
          }else{
            String secondMangle = "[" + searched + ";"; //$NON-NLS-1$ //$NON-NLS-2$
            if (secondMangle.equals(signature)){
              count++;
              if (javaClass.isArray()){
                vctr.add((byte)3);
              }else if (isInterface(javaClass.getID().getAddress())){
                vctr.add((byte)2);
              }else{
                vctr.add((byte)1);
              }
              //vctr.add((byte)1);
              addLongToVector(vctr, javaClass.getID().getAddress());
              //Verified Prepared and Initialized
              addIntToVector(vctr, 1 | 2 | 4);
              logr.log(JDILogger.LEVEL_VERYVERBOSE, "Really mangled match: " + javaClass.getName()); //$NON-NLS-1$
            }
          }
        }

      }
      //Add the count to the front of the vector
      addIntToVectorFront(vctr, count);
      logr.log(JDILogger.LEVEL_VERYVERBOSE, count+" matches"); //$NON-NLS-1$
      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
      rpckt.setData(vectorToByte(vctr));
      return rpckt;
    }else if (cpckt.getCommand() == VIRTUAL_MACHINE_ALL_CLASSES){
      logr.log(JDILogger.LEVEL_VERBOSE, "AllClasses()"); //$NON-NLS-1$
      Vector<Byte> vctr = new Vector<Byte>();
      int count = 0;
      Iterator <JavaClass> classList = classes.values().iterator();
      while(classList.hasNext()){
        JavaClass javaClass = (JavaClass)classList.next();
        long typeID = javaClass.getID().getAddress();
        String signature;

        if (javaClass.isArray()){
          vctr.add((byte)3);
          signature = "" + javaClass.getName() + ""; //$NON-NLS-1$ //$NON-NLS-2$
        }else if (isInterface(typeID)){
          vctr.add((byte)2);
          signature = "L" + javaClass.getName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        }else{
          vctr.add((byte)1);
          signature = "L" + javaClass.getName() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        }
       
        int status = 7;
        addLongToVector(vctr, typeID);
        addStringToVector(vctr, signature);
View Full Code Here

          break;
        }

        JavaObject aJavaObject = (JavaObject) nextObject;
        try {
          JavaClass theJavaClass = aJavaObject.getJavaClass();
          String theClassName = (theJavaClass).getName();
          if (theClassName.equals(SetupJavaObject_getDeclaredFields_getName.TestObjectClassName)){

            Iterator fields = theJavaClass.getDeclaredFields().iterator();

            while (fields.hasNext()) {
              Object nextField = fields.next();

              if (nextField instanceof CorruptData) {
View Full Code Here

      throw new IllegalArgumentException("Passed object must be CJVMTI JObject instance");
    }
   
    JObject stringObj = (JObject) obj;
   
    JavaClass stringClass = stringObj.getJavaClass();
   
    // java.lang.String is final.
    if(!stringClass.getName().equals("java/lang/String")) {
      throw new IllegalArgumentException("Field must be instance of java/lang/String");
    }
   

    JavaField valueField=null, countField=null, offsetField=null;
View Full Code Here

      Vector<Byte> vctr = new Vector<Byte>();
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Signature(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        if (javaClass.isArray()){
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "" + javaClass.getName() + ""); //$NON-NLS-1$ //$NON-NLS-2$
          addStringToVector(vctr, "" + javaClass.getName() + ""); //$NON-NLS-1$ //$NON-NLS-2$
        }else{
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "L" + javaClass.getName() + ";"); //$NON-NLS-1$ //$NON-NLS-2$
          addStringToVector(vctr, "L" + javaClass.getName() + ";");
        } //$NON-NLS-1$ //$NON-NLS-2$
        ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
        rpckt.setData(vectorToByte(vctr));
        return rpckt;
      }

      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_CLASS_LOADER){
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "ClassLoader(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        Vector<Byte> vctr = new Vector<Byte>();
        JavaObject obj = javaClass.getClassLoader().getObject();
        long address = 0L;
       
        if (obj != null) {
          address = obj.getID().getAddress();
        }
       
        addLongToVector(vctr, address);
        logr.log(JDILogger.LEVEL_VERYVERBOSE, "  0x" + Long.toHexString(address) ); //$NON-NLS-1$
        ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
        rpckt.setData(vectorToByte(vctr));
        return rpckt;

      }

      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_MODIFIERS){
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Modifiers(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        Vector<Byte> vctr = new Vector<Byte>();
        addIntToVectorFront(vctr,javaClass.getModifiers());
        ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
        rpckt.setData(vectorToByte(vctr));
        return rpckt;
      }

      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_FIELDS){
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Fields(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        Iterator javaFields = javaClass.getDeclaredFields().iterator();
        logr.log(JDILogger.LEVEL_VERYVERBOSE, javaClass.getName() + ":"); //$NON-NLS-1$
        Vector<Byte> vctr = new Vector<Byte>();
        int count = 0;
        while (javaFields.hasNext()){
          JavaField jField = (JavaField)javaFields.next();

          long fieldID = getFieldId(refType, jField);
          String name = jField.getName();
          String signature = jField.getSignature();
          int modBits = jField.getModifiers();
          addLongToVector(vctr, fieldID);
          addStringToVector(vctr, name);
          addStringToVector(vctr, signature);
          addIntToVector(vctr, modBits);
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "  " + name + " (" + signature + "," + fieldID + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          count++;
        }
        addIntToVectorFront(vctr,count);
        logr.log(JDILogger.LEVEL_VERYVERBOSE, "Found " + count + " fields(s)"); //$NON-NLS-1$ //$NON-NLS-2$
        ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
        rpckt.setData(vectorToByte(vctr));
        return rpckt;
      }

      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_METHODS){
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Methods(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        Iterator javaMethods = javaClass.getDeclaredMethods().iterator();
        logr.log(JDILogger.LEVEL_VERYVERBOSE, javaClass.getName() + ":"); //$NON-NLS-1$
        Vector<Byte> vctr = new Vector<Byte>();
        int count = 0;
        while (javaMethods.hasNext()){
          JavaMethod jMethod = (JavaMethod)javaMethods.next();
          long methodID = getMethodId(refType, jMethod);
          String name = jMethod.getName();
          String signature = jMethod.getSignature();
          int modBits = jMethod.getModifiers();
          addLongToVector(vctr, methodID);
          addStringToVector(vctr, name);
          addStringToVector(vctr, signature);
          addIntToVector(vctr, modBits);
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "  " + name + " (" + signature + ", " + methodID + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
          count++;
        }
        addIntToVectorFront(vctr,count);
        logr.log(JDILogger.LEVEL_VERYVERBOSE, "Found " + count + " method(s)"); //$NON-NLS-1$ //$NON-NLS-2$
        ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
        rpckt.setData(vectorToByte(vctr));
        return rpckt;
      }


      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_GET_VALUES){
      byte [] inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      int fields = createIntFromBytes(inData, 8, 4);
      logr.log(JDILogger.LEVEL_VERBOSE, "ReferenceType.GetValues(" + refType + ", " + fields + ",...)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
      Vector<Byte> vctr = new Vector<Byte>();

      addIntToVector(vctr, fields);

      for(int i = 0; i < fields; i++){
        long fieldID = createLongFromBytes(inData, 12 + (i * 8), 8);
        logr.log(JDILogger.LEVEL_VERYVERBOSE, "  " + i + " of " + fields + " {" + fieldID+"}"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        if (!getFieldFromClass(vctr, refType, fieldID)){
          ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_INVALID_OBJECT);
          return rpckt;
        }
      }
      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
      rpckt.setData(vectorToByte(vctr));
      return rpckt;
    }else if (cpckt.getCommand() == REFERENCE_TYPE_SOURCE_FILE){
      byte [] inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "SourceFile(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$
      Iterator asIt = image.getAddressSpaces( ).iterator();
      while ( asIt.hasNext( ) )
      {
        ImageAddressSpace as = (ImageAddressSpace) asIt.next( );
        Iterator prIt = as.getProcesses( ).iterator();

        while ( prIt.hasNext( ) )
        {
          ImageProcess process = (ImageProcess) prIt.next( );
          Iterator runTimesIt = process.getRuntimes( ).iterator();
          while ( runTimesIt.hasNext( ) )
          {
            JavaRuntime javaRT = (JavaRuntime) runTimesIt.next( );
            Iterator thds = javaRT.getThreads().iterator();
            while(thds.hasNext()){
              Object tmpobj = thds.next();
              if (tmpobj instanceof CorruptData){
                //ignore this thread
              }else{
                JavaThread thd = (JavaThread) tmpobj;
                Iterator frames = thd.getStackFrames().iterator();
                while(frames.hasNext()){
                  JavaStackFrame jStackFrame = (JavaStackFrame)frames.next();
                  JavaLocation jLocation = jStackFrame.getLocation();
                  JavaMethod jMethod = jLocation.getMethod();
                  JavaClass jClass = jMethod.getDeclaringClass();


                  if (jClass.getID().getAddress() == refType){
                    Vector<Byte> vctr = new Vector<Byte>();
                    try{
                      addStringToVector(vctr, jLocation.getFilename());
                      logr.log(JDILogger.LEVEL_VERBOSE, "  " + jLocation.getFilename()); //$NON-NLS-1$
                      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
                      rpckt.setData(vectorToByte(vctr));
                      return rpckt;
                    }
                    catch(Exception exxy){
                      logr.log(JDILogger.LEVEL_VERYVERBOSE, "  Missing source file name information"); //$NON-NLS-1$
                      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_ABSENT_INFORMATION);
                      return rpckt;
                    }
                  }
                }
              }
            }
          }
        }
      }
      logr.log(JDILogger.LEVEL_VERYVERBOSE, "  Not on stack, cannot retrieve information"); //$NON-NLS-1$
      ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_ABSENT_INFORMATION);
      return rpckt;

    }else if (cpckt.getCommand() == REFERENCE_TYPE_INTERFACES){
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Interfaces(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        Iterator javaInterfaces = javaClass.getInterfaces().iterator();
        logr.log(JDILogger.LEVEL_VERYVERBOSE, javaClass.getName() + ":"); //$NON-NLS-1$
        Vector<Byte> vctr = new Vector<Byte>();
        int count = 0;
        while (javaInterfaces.hasNext()){
          String iFaceName = (String)javaInterfaces.next();
        JavaClass jClass = javaClass.getClassLoader().findClass(iFaceName);
          long interfaceID;
          if (jClass == null){
            interfaceID = 0;
          }else{
            interfaceID = jClass.getID().getAddress();
          }
          addLongToVector(vctr, interfaceID);
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "  " + interfaceID); //$NON-NLS-1$

          count++;
View Full Code Here

      Vector<Byte> vctr = new Vector<Byte>();
      byte []inData = cpckt.getByteData();
      long refType = createLongFromBytes(inData, 0, 8);
      logr.log(JDILogger.LEVEL_VERBOSE, "Superclass(" + refType + ")"); //$NON-NLS-1$ //$NON-NLS-2$

      JavaClass javaClass = getClass(refType);
      if (javaClass != null){
        JavaClass jSuperClass = javaClass.getSuperclass();
        if( jSuperClass != null) {
          addLongToVector(vctr, jSuperClass.getID().getAddress());
          logr.log(JDILogger.LEVEL_VERYVERBOSE, "  " + jSuperClass.getID().getAddress()); //$NON-NLS-1$
          ReplyPacket rpckt = new ReplyPacket(cpckt.getSequence(), FLAG_REPLY_PACKET, ERROR_NONE);
          rpckt.setData(vectorToByte(vctr));
          return rpckt;
        } else {
          addLongToVector(vctr, 0);
View Full Code Here

TOP

Related Classes of javax.tools.diagnostics.runtime.java.JavaClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.