コード例 #1
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 /**
  * Gets the super class of this class.
  *
  * @return the super class of this class
  */
 public final ProxyType getSuperclass() throws IOException, SDWPException {
   Klass superClass = klass.getSuperclass();
   // the "-bytecode-" class actually inherits from INT, but don't tell jdwp that!
   if (superClass != null && !superClass.isPrimitive()) {
     return ptm.lookup(superClass, true);
   }
   return null;
 }
コード例 #2
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 @SuppressWarnings("unchecked")
 private void addFields(List list, boolean isStatic) {
   int count = klass.getFieldCount(isStatic);
   for (int i = 0; i != count; ++i) {
     Field field = klass.getField(i, isStatic);
     FieldID fid = new FieldID(JDWP.getTag(field.getType()), field.getOffset(), isStatic, getID());
     ProxyField proxyField = new ProxyField(fid, field);
     list.add(proxyField);
   }
 }
コード例 #3
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 @SuppressWarnings("unchecked")
 private void addMethods(List list, boolean isStatic) {
   int count = klass.getMethodCount(isStatic);
   for (int i = 0; i != count; ++i) {
     Method method = klass.getMethod(i, isStatic);
     if (!method.isHosted()) {
       MethodID mid = new MethodID(method.getOffset(), isStatic);
       ProxyMethod proxyMethod = new ProxyMethod(mid, method);
       list.add(proxyMethod);
     }
   }
 }
コード例 #4
0
ファイル: ProxyType.java プロジェクト: johangas/moped
  /**
   * Gets the fully qualified name of this type. The returned name is formatted as it might appear
   * in a Java programming language declaration for objects of this type.
   *
   * <p>For primitive classes the returned name is the name of the corresponding primitive type; for
   * example, "int" is returned as the name of the class represented by {@link
   * java.lang.Integer#TYPE Integer.TYPE}.
   *
   * @return a string containing the type name.
   */
  public String getName() {
    String name = klass.getName();
    if (!klass.isArray()) {
      return name;
    }

    int dimensions = 0;
    while (name.charAt(dimensions) == '[') {
      ++dimensions;
    }

    name = name.substring(dimensions);
    char first = name.charAt(0);
    if (first == 'L') {
      name = name.substring(1, name.length() - 2).replace('/', '.');
    } else {
      switch (first) {
        case 'I':
          name = "int";
          break;
        case 'J':
          name = "long";
          break;
        case 'F':
          name = "float";
          break;
        case 'D':
          name = "double";
          break;
        case 'Z':
          name = "boolean";
          break;
        case 'C':
          name = "char";
          break;
        case 'S':
          name = "short";
          break;
        case 'B':
          name = "byte";
          break;
        case 'V':
          name = "void";
          break;
      }
    }
    while (dimensions-- != 0) {
      name += "[]";
    }
    return name;
  }
コード例 #5
0
 boolean computeSubtypeOf(Klass k) {
   if (k.isInterface()) {
     return implementsInterface(k);
   } else {
     return super.computeSubtypeOf(k);
   }
 }
コード例 #6
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 /**
  * Returns interfaces directly implemented by this type.
  *
  * @return a List of the interfaces directly implemented by this type
  */
 @SuppressWarnings("unchecked")
 public List getInterfaces() throws IOException, SDWPException {
   Klass[] interfaces = klass.getInterfaces();
   List list = new ArrayList(interfaces.length);
   for (int i = 0; i != interfaces.length; ++i) {
     list.add(ptm.lookup(interfaces[i], true));
   }
   return list;
 }
コード例 #7
0
 public void iterateFields(OopVisitor visitor, boolean doVMFields) {
   super.iterateFields(visitor, doVMFields);
   if (doVMFields) {
     visitor.doCInt(dimension, true);
     visitor.doOop(higherDimension, true);
     visitor.doOop(lowerDimension, true);
     visitor.doCInt(vtableLen, true);
     visitor.doCInt(allocSize, true);
     visitor.doOop(componentMirror, true);
   }
 }
コード例 #8
0
 public boolean implementsInterface(Klass k) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(k.isInterface(), "should not reach here");
   }
   ObjArray interfaces = getTransitiveInterfaces();
   final int len = (int) interfaces.getLength();
   for (int i = 0; i < len; i++) {
     if (interfaces.getObjAt(i).equals(k)) return true;
   }
   return false;
 }
コード例 #9
0
 boolean computeSubtypeOf(Klass k) {
   // An array is a subtype of Serializable, Clonable, and Object
   Symbol name = k.getName();
   if (name != null
       && (name.equals(javaIoSerializableName())
           || name.equals(javaLangCloneableName())
           || name.equals(javaLangObjectName()))) {
     return true;
   } else {
     return false;
   }
 }
コード例 #10
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 /**
  * Returns a list containing each {@link Method} declared directly in this type. Inherited methods
  * are not included. Constructors, the initialization method if any, and any synthetic methods
  * created by the compiler are included in the list.
  *
  * <p>For arrays and primitive classes, the returned list is always empty.
  *
  * @return a list {@link Method} objects; the list has length 0 if no methods exist.
  */
 public List getMethods() {
   if (methods == null) {
     if (klass.isArray()) {
       methods = Collections.EMPTY_LIST;
     } else {
       methods = new ArrayList();
       addMethods(methods, true);
       addMethods(methods, false);
     }
   }
   return methods;
 }
コード例 #11
0
  public void iterateFields(OopVisitor visitor, boolean doVMFields) {
    super.iterateFields(visitor, doVMFields);
    if (doVMFields) {
      visitor.doOop(arrayKlasses, true);
      visitor.doOop(methods, true);
      visitor.doOop(methodOrdering, true);
      visitor.doOop(localInterfaces, true);
      visitor.doOop(transitiveInterfaces, true);
      visitor.doCInt(nofImplementors, true);
      for (int i = 0; i < IMPLEMENTORS_LIMIT; i++) visitor.doOop(implementors[i], true);
      visitor.doOop(fields, true);
      visitor.doOop(constants, true);
      visitor.doOop(classLoader, true);
      visitor.doOop(protectionDomain, true);
      visitor.doOop(signers, true);
      visitor.doOop(sourceFileName, true);
      visitor.doOop(innerClasses, true);
      visitor.doCInt(nonstaticFieldSize, true);
      visitor.doCInt(staticFieldSize, true);
      visitor.doCInt(staticOopFieldSize, true);
      visitor.doCInt(nonstaticOopMapSize, true);
      visitor.doCInt(isMarkedDependent, true);
      visitor.doCInt(initState, true);
      visitor.doCInt(vtableLen, true);
      visitor.doCInt(itableLen, true);
    }

    TypeArray fields = getFields();
    int length = (int) fields.getLength();
    for (int index = 0; index < length; index += NEXT_OFFSET) {
      short accessFlags = fields.getShortAt(index + ACCESS_FLAGS_OFFSET);
      short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
      FieldType type = new FieldType((Symbol) getConstants().getObjAt(signatureIndex));
      AccessFlags access = new AccessFlags(accessFlags);
      if (access.isStatic()) {
        visitField(visitor, type, index);
      }
    }
  }
コード例 #12
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 /**
  * Gets an identifying name for the source corresponding to the declaration of this type.
  * Interpretation of this string is the responsibility of the source repository mechanism.
  *
  * <p>The returned name is dependent on VM's default stratum ({@link
  * VirtualMachine#getDefaultStratum()}). In the reference implementation, when using the base
  * stratum, the returned string is the unqualified name of the source file containing the
  * declaration of this type. In other strata the returned source name is the first source name for
  * that stratum. Since other languages may have more than one source name for a reference type,
  * the use of {@link Location#sourceName()} or {@link #sourceNames(String)} is preferred.
  *
  * <p>
  *
  * @return the string source file name or null if it is not known
  */
 public String getSourceName() {
   return klass.getSourceFileName();
 }
コード例 #13
0
ファイル: ProxyType.java プロジェクト: johangas/moped
 /**
  * Returns the modifiers for the reference type. ACC_PUBLIC, ACC_FINAL, etc. Undefined for arrays
  * and primitive type.
  *
  * @return the class modifiers in JVM Spec format.
  */
 public int getModifiers() {
   return klass.getModifiers() & Modifier.getJVMClassModifiers();
 }
コード例 #14
0
  public void writeBytes(OutputStream os) throws IOException {
    // Map between any modified UTF-8 and it's constant pool index.
    Map utf8ToIndex = new HashMap();
    DataOutputStream dos = new DataOutputStream(os);
    TypeArray tags = getTags();
    int len = (int) getLength();
    int ci = 0; // constant pool index

    // collect all modified UTF-8 Strings from Constant Pool

    for (ci = 1; ci < len; ci++) {
      byte cpConstType = tags.getByteAt(ci);
      if (cpConstType == JVM_CONSTANT_Utf8) {
        Symbol sym = getSymbolAt(ci);
        utf8ToIndex.put(sym.asString(), new Short((short) ci));
      } else if (cpConstType == JVM_CONSTANT_Long || cpConstType == JVM_CONSTANT_Double) {
        ci++;
      }
    }

    for (ci = 1; ci < len; ci++) {
      int cpConstType = (int) tags.getByteAt(ci);
      // write cp_info
      // write constant type
      switch (cpConstType) {
        case JVM_CONSTANT_Utf8:
          {
            dos.writeByte(cpConstType);
            Symbol sym = getSymbolAt(ci);
            dos.writeShort((short) sym.getLength());
            dos.write(sym.asByteArray());
            if (DEBUG) debugMessage("CP[" + ci + "] = modified UTF-8 " + sym.asString());
            break;
          }

        case JVM_CONSTANT_Unicode:
          throw new IllegalArgumentException("Unicode constant!");

        case JVM_CONSTANT_Integer:
          dos.writeByte(cpConstType);
          dos.writeInt(getIntAt(ci));
          if (DEBUG) debugMessage("CP[" + ci + "] = int " + getIntAt(ci));
          break;

        case JVM_CONSTANT_Float:
          dos.writeByte(cpConstType);
          dos.writeFloat(getFloatAt(ci));
          if (DEBUG) debugMessage("CP[" + ci + "] = float " + getFloatAt(ci));
          break;

        case JVM_CONSTANT_Long:
          {
            dos.writeByte(cpConstType);
            long l = getLongAt(ci);
            // long entries occupy two pool entries
            ci++;
            dos.writeLong(l);
            break;
          }

        case JVM_CONSTANT_Double:
          dos.writeByte(cpConstType);
          dos.writeDouble(getDoubleAt(ci));
          // double entries occupy two pool entries
          ci++;
          break;

        case JVM_CONSTANT_Class:
          {
            dos.writeByte(cpConstType);
            // Klass already resolved. ConstantPool constains klassOop.
            Klass refKls = (Klass) getObjAt(ci);
            String klassName = refKls.getName().asString();
            Short s = (Short) utf8ToIndex.get(klassName);
            dos.writeShort(s.shortValue());
            if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
            break;
          }

          // case JVM_CONSTANT_ClassIndex:
        case JVM_CONSTANT_UnresolvedClass:
          {
            dos.writeByte(JVM_CONSTANT_Class);
            String klassName = getSymbolAt(ci).asString();
            Short s = (Short) utf8ToIndex.get(klassName);
            dos.writeShort(s.shortValue());
            if (DEBUG) debugMessage("CP[" + ci + "] = class " + s);
            break;
          }

        case JVM_CONSTANT_String:
          {
            dos.writeByte(cpConstType);
            String str = OopUtilities.stringOopToString(getObjAt(ci));
            Short s = (Short) utf8ToIndex.get(str);
            dos.writeShort(s.shortValue());
            if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
            break;
          }

          // case JVM_CONSTANT_StringIndex:
        case JVM_CONSTANT_UnresolvedString:
          {
            dos.writeByte(JVM_CONSTANT_String);
            String val = getSymbolAt(ci).asString();

            Short s = (Short) utf8ToIndex.get(val);
            dos.writeShort(s.shortValue());
            if (DEBUG) debugMessage("CP[" + ci + "] = string " + s);
            break;
          }

          // all external, internal method/field references
        case JVM_CONSTANT_Fieldref:
        case JVM_CONSTANT_Methodref:
        case JVM_CONSTANT_InterfaceMethodref:
          {
            dos.writeByte(cpConstType);
            int value = getIntAt(ci);
            short klassIndex = (short) extractLowShortFromInt(value);
            short nameAndTypeIndex = (short) extractHighShortFromInt(value);
            dos.writeShort(klassIndex);
            dos.writeShort(nameAndTypeIndex);
            if (DEBUG)
              debugMessage(
                  "CP[" + ci + "] = ref klass = " + klassIndex + ", N&T = " + nameAndTypeIndex);
            break;
          }

        case JVM_CONSTANT_NameAndType:
          {
            dos.writeByte(cpConstType);
            int value = getIntAt(ci);
            short nameIndex = (short) extractLowShortFromInt(value);
            short signatureIndex = (short) extractHighShortFromInt(value);
            dos.writeShort(nameIndex);
            dos.writeShort(signatureIndex);
            if (DEBUG)
              debugMessage(
                  "CP[" + ci + "] = N&T name = " + nameIndex + ", type = " + signatureIndex);
            break;
          }
      } // switch
    }
    dos.flush();
    return;
  }