Esempio n. 1
0
 // secondary entries hold invokedynamic call site bindings
 public ConstantPoolCacheEntry getSecondaryEntryAt(int i) {
   ConstantPoolCacheEntry e = new ConstantPoolCacheEntry(this, decodeSecondaryIndex(i));
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(e.isSecondaryEntry(), "must be a secondary entry");
   }
   return e;
 }
Esempio n. 2
0
  /**
   * Helper method that creates an array of bytes for the specified <tt>Set</tt> of <tt>URN</tt>
   * instances. The bytes are written as specified in HUGE v 0.94.
   *
   * @param urns the <tt>Set</tt> of <tt>URN</tt> instances to use in constructing the byte array
   */
  private static byte[] createExtBytes(Set urns, GGEPContainer ggep) {
    try {
      if (isEmpty(urns) && ggep.isEmpty()) return DataUtils.EMPTY_BYTE_ARRAY;

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      if (!isEmpty(urns)) {
        // Add the extension for URNs, if any.
        Iterator iter = urns.iterator();
        while (iter.hasNext()) {
          URN urn = (URN) iter.next();
          Assert.that(urn != null, "Null URN");
          baos.write(urn.toString().getBytes());
          // If there's another URN, add the separator.
          if (iter.hasNext()) {
            baos.write(EXT_SEPARATOR);
          }
        }

        // If there's ggep data, write the separator.
        if (!ggep.isEmpty()) baos.write(EXT_SEPARATOR);
      }

      // It is imperitive that GGEP is added LAST.
      // That is because GGEP can contain 0x1c (EXT_SEPARATOR)
      // within it, which would cause parsing problems
      // otherwise.
      if (!ggep.isEmpty()) GGEPUtil.addGGEP(baos, ggep);

      return baos.toByteArray();
    } catch (IOException impossible) {
      ErrorService.error(impossible);
      return DataUtils.EMPTY_BYTE_ARRAY;
    }
  }
 // "size helper" == instance size in words
 public long getSizeHelper() {
   int lh = getLayoutHelper();
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(lh > 0, "layout helper initialized for instance class");
   }
   return lh / VM.getVM().getAddressSize();
 }
Esempio n. 4
0
  private static void initialize(TypeDataBase db) {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(!VM.getVM().isCore(), "Debug info not used in core build");
    }

    OFFSET_MASK = db.lookupIntConstant("Location::OFFSET_MASK").intValue();
    OFFSET_SHIFT = db.lookupIntConstant("Location::OFFSET_SHIFT").intValue();
    TYPE_MASK = db.lookupIntConstant("Location::TYPE_MASK").intValue();
    TYPE_SHIFT = db.lookupIntConstant("Location::TYPE_SHIFT").intValue();
    WHERE_MASK = db.lookupIntConstant("Location::WHERE_MASK").intValue();
    WHERE_SHIFT = db.lookupIntConstant("Location::WHERE_SHIFT").intValue();

    // Location::Type constants
    TYPE_NORMAL = db.lookupIntConstant("Location::normal").intValue();
    TYPE_OOP = db.lookupIntConstant("Location::oop").intValue();
    TYPE_NARROWOOP = db.lookupIntConstant("Location::narrowoop").intValue();
    TYPE_INT_IN_LONG = db.lookupIntConstant("Location::int_in_long").intValue();
    TYPE_LNG = db.lookupIntConstant("Location::lng").intValue();
    TYPE_FLOAT_IN_DBL = db.lookupIntConstant("Location::float_in_dbl").intValue();
    TYPE_DBL = db.lookupIntConstant("Location::dbl").intValue();
    TYPE_ADDR = db.lookupIntConstant("Location::addr").intValue();
    TYPE_INVALID = db.lookupIntConstant("Location::invalid").intValue();

    // Location::Where constants
    WHERE_ON_STACK = db.lookupIntConstant("Location::on_stack").intValue();
    WHERE_IN_REGISTER = db.lookupIntConstant("Location::in_register").intValue();
  }
Esempio n. 5
0
 public int getFieldOrMethodAt(int which) {
   if (DEBUG) {
     System.err.print("ConstantPool.getFieldOrMethodAt(" + which + "): new index = ");
   }
   int i = -1;
   ConstantPoolCache cache = getCache();
   if (cache == null) {
     i = which;
   } else {
     // change byte-ordering and go via cache
     i =
         cache
             .getEntryAt(0xFFFF & VM.getVM().getBytes().swapShort((short) which))
             .getConstantPoolIndex();
   }
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getTagAt(i).isFieldOrMethod(), "Corrupted constant pool");
   }
   if (DEBUG) {
     System.err.println(i);
   }
   int res = getIntAt(i);
   if (DEBUG) {
     System.err.println("ConstantPool.getFieldOrMethodAt(" + i + "): result = " + res);
   }
   return res;
 }
  /**
   * Return a List of SA Fields for all the java fields in this class, including all inherited
   * fields. This includes hidden fields. Thus the returned list can contain fields with the same
   * name. Return an empty list if there are no fields. Only designed for use in a debugging system.
   */
  public List getAllFields() {
    // Contains a Field for each field in this class, including immediate
    // fields and inherited fields.
    List allFields = getImmediateFields();

    // transitiveInterfaces contains all interfaces implemented
    // by this class and its superclass chain with no duplicates.

    ObjArray interfaces = getTransitiveInterfaces();
    int n = (int) interfaces.getLength();
    for (int i = 0; i < n; i++) {
      InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(intf1.isInterface(), "just checking type");
      }
      allFields.addAll(intf1.getImmediateFields());
    }

    // Get all fields in the superclass, recursively.  But, don't
    // include fields in interfaces implemented by superclasses;
    // we already have all those.
    if (!isInterface()) {
      InstanceKlass supr;
      if ((supr = (InstanceKlass) getSuper()) != null) {
        allFields.addAll(supr.getImmediateFields());
      }
    }

    return allFields;
  }
Esempio n. 7
0
 private long indexOffset(long index) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(
         index > 0 && index < getLength(), "invalid cp index " + index + " " + getLength());
   }
   return (index * getElementSize()) + headerSize;
 }
Esempio n. 8
0
 /** Sets this bitmap to the contents of the argument. Both bitmaps must be the same size. */
 public void setFrom(BitMap other) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(size() == other.size(), "must have same size");
   }
   for (int index = 0; index < sizeInWords(); index++) {
     data[index] = other.data[index];
   }
 }
Esempio n. 9
0
 public E next() {
   if (!hasNext()) {
     throw new NoSuchElementException();
   }
   Neighbor neighbor = list;
   list = neighbor.next;
   Assert.that(neighbor.level == 0);
   return (E) neighbor.child;
 }
Esempio n. 10
0
 /** Both bitmaps must be the same size. */
 public boolean isSame(BitMap other) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(size() == other.size(), "must have same size");
   }
   for (int index = 0; index < sizeInWords(); index++) {
     if (data[index] != (other.data[index])) return false;
   }
   return true;
 }
Esempio n. 11
0
 public int getNameAndTypeAt(int which) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getTagAt(which).isNameAndType(), "Corrupted constant pool");
   }
   int i = getIntAt(which);
   if (DEBUG) {
     System.err.println("ConstantPool.getNameAndTypeAt(" + which + "): result = " + i);
   }
   return i;
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 public ConstantPoolCacheEntry getMainEntryAt(int i) {
   if (isSecondaryIndex(i)) {
     // run through an extra level of indirection:
     i = getSecondaryEntryAt(i).getMainEntryIndex();
   }
   ConstantPoolCacheEntry e = new ConstantPoolCacheEntry(this, i);
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(!e.isSecondaryEntry(), "must not be a secondary entry");
   }
   return e;
 }
Esempio n. 14
0
 public ThreadContext getContext() throws IllegalThreadStateException {
   DbxSPARCThreadContext context = new DbxSPARCThreadContext(debugger);
   long[] regs = debugger.getThreadIntegerRegisterSet(id);
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(regs.length == SPARCThreadContext.NPRGREG, "size of register set must match");
   }
   for (int i = 0; i < regs.length; i++) {
     context.setRegister(i, regs[i]);
   }
   return context;
 }
Esempio n. 15
0
 /**
  * Sets this bitmap to the logical union of it and the argument. Both bitmaps must be the same
  * size. Returns true if a change was caused in this bitmap.
  */
 public boolean setUnion(BitMap other) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(size() == other.size(), "must have same size");
   }
   boolean changed = false;
   for (int index = 0; index < sizeInWords(); index++) {
     int temp = data[index] | other.data[index];
     changed = changed || (temp != data[index]);
     data[index] = temp;
   }
   return changed;
 }
Esempio n. 16
0
 /**
  * Fetch the original non-breakpoint bytecode at the specified bci. It is required that there is
  * currently a bytecode at this bci.
  */
 public int getOrigBytecodeAt(int bci) {
   BreakpointInfo bp = ((InstanceKlass) getMethodHolder()).getBreakpoints();
   for (; bp != null; bp = bp.getNext()) {
     if (bp.match(this, bci)) {
       return bp.getOrigBytecode();
     }
   }
   System.err.println("Requested bci " + bci);
   for (; bp != null; bp = bp.getNext()) {
     System.err.println("Breakpoint at bci " + bp.getBCI() + ", bytecode " + bp.getOrigBytecode());
   }
   Assert.that(false, "Should not reach here");
   return -1; // not reached
 }
Esempio n. 17
0
 /** Find field in direct superinterfaces. */
 public Field findInterfaceField(Symbol name, Symbol sig) {
   ObjArray interfaces = getLocalInterfaces();
   int n = (int) interfaces.getLength();
   for (int i = 0; i < n; i++) {
     InstanceKlass intf1 = (InstanceKlass) interfaces.getObjAt(i);
     if (Assert.ASSERTS_ENABLED) {
       Assert.that(intf1.isInterface(), "just checking type");
     }
     // search for field in current interface
     Field f = intf1.findLocalField(name, sig);
     if (f != null) {
       if (Assert.ASSERTS_ENABLED) {
         Assert.that(f.getAccessFlagsObj().isStatic(), "interface field must be static");
       }
       return f;
     }
     // search for field in direct superinterfaces
     f = intf1.findInterfaceField(name, sig);
     if (f != null) return f;
   }
   // otherwise field lookup fails
   return null;
 }
  /** Only returns addresses of valid OopHandles */
  private Address getOopHandleAddress(int x) {
    if (Assert.ASSERTS_ENABLED) {
      Assert.that(x < top(), "out of bounds");
    }

    Address oopAddr = addr.addOffsetTo(handlesField.getOffset() + x * VM.getVM().getOopSize());
    OopHandle handle = oopAddr.getOopHandleAt(0);
    if (VM.getVM().getUniverse().isInReserved(handle)
        && !VM.getVM().getJNIHandles().isDeletedHandle(handle)) {
      /* the oop handle is valid only if it is not freed (i.e. reserved in heap) and is not a deleted oop */
      return oopAddr;
    } else {
      return null;
    }
  }
Esempio n. 19
0
  public int getClassStatus() {
    int result = 0;
    if (isLinked()) {
      result |= JVMDIClassStatus.VERIFIED | JVMDIClassStatus.PREPARED;
    }

    if (isInitialized()) {
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(isLinked(), "Class status is not consistent");
      }
      result |= JVMDIClassStatus.INITIALIZED;
    }

    if (isInErrorState()) {
      result |= JVMDIClassStatus.ERROR;
    }
    return result;
  }
 public Klass arrayKlassImpl(boolean orNull, int n) {
   int dimension = (int) getDimension();
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(dimension <= n, "check order of chain");
   }
   if (dimension == n) return this;
   ObjArrayKlass ak = (ObjArrayKlass) getHigherDimension();
   if (ak == null) {
     if (orNull) return null;
     // FIXME: would need to change in reflective system to actually
     // allocate klass
     throw new RuntimeException("Can not allocate array klasses in debugging system");
   }
   if (orNull) {
     return ak.arrayKlassOrNull(n);
   }
   return ak.arrayKlass(n);
 }
Esempio n. 21
0
  // refer to compute_modifier_flags in VM code.
  public long computeModifierFlags() {
    long access = getAccessFlags();
    // But check if it happens to be member class.
    TypeArray innerClassList = getInnerClasses();
    int length = (innerClassList == null) ? 0 : (int) innerClassList.getLength();
    if (length > 0) {
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking");
      }
      for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
        int ioff =
            innerClassList.getShortAt(i + InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
        // 'ioff' can be zero.
        // refer to JVM spec. section 4.7.5.
        if (ioff != 0) {
          // only look at classes that are already loaded
          // since we are looking for the flags for our self.
          Oop classInfo = getConstants().getObjAt(ioff);
          Symbol name = null;
          if (classInfo instanceof Klass) {
            name = ((Klass) classInfo).getName();
          } else if (classInfo instanceof Symbol) {
            name = (Symbol) classInfo;
          } else {
            throw new RuntimeException("should not reach here");
          }

          if (name.equals(getName())) {
            // This is really a member class
            access =
                innerClassList.getShortAt(
                    i + InnerClassAttributeOffset.innerClassAccessFlagsOffset);
            break;
          }
        }
      } // for inner classes
    }

    // Remember to strip ACC_SUPER bit
    return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
  }
 public FieldType(Symbol signature) {
   this.signature = signature;
   this.first = (char) signature.getByteAt(0);
   if (Assert.ASSERTS_ENABLED) {
     switch (this.first) {
       case 'B':
       case 'C':
       case 'D':
       case 'F':
       case 'I':
       case 'J':
       case 'S':
       case 'Z':
       case 'L':
       case '[':
         break; // Ok. signature char known
       default:
         Assert.that(
             false,
             "Unknown char in field signature \"" + signature.asString() + "\": " + this.first);
     }
   }
 }
Esempio n. 23
0
 // Accessors
 public boolean at(int offset) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(offset >= 0 && offset < size(), "BitMap index out of bounds");
   }
   return Bits.isSetNthBit(wordFor(offset), offset % bitsPerWord);
 }
Esempio n. 24
0
 public ConstantPoolCacheEntry getEntryAt(int i) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(0 <= i && i < getLength(), "index out of bounds");
   }
   return new ConstantPoolCacheEntry(this, i);
 }
Esempio n. 25
0
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check fast_aaccess_0");
   }
 }
Esempio n. 26
0
 public int getRegisterNumber() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.IN_REGISTER, "wrong Where");
   }
   return getOffset();
 }
Esempio n. 27
0
 public int getStackOffset() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.ON_STACK, "wrong Where");
   }
   return getOffset() * (int) VM.getVM().getIntSize();
 }
Esempio n. 28
0
 /**
  * Creates a ProxyType for a class.
  *
  * @param klass the class
  * @param id the JDWP identifier for the class
  * @param ptm the object that created this proxy type and is used to lookup other proxy types
  */
 ProxyType(Klass klass, ReferenceTypeID id, ProxyTypeManager ptm) {
   this.ptm = ptm;
   this.id = id;
   Assert.that(klass != null);
   this.klass = klass;
 }
Esempio n. 29
0
  private boolean isInInnerClasses(Symbol sym, boolean includeLocals) {
    TypeArray innerClassList = getInnerClasses();
    int length = (innerClassList == null) ? 0 : (int) innerClassList.getLength();
    if (length > 0) {
      if (Assert.ASSERTS_ENABLED) {
        Assert.that(length % InnerClassAttributeOffset.innerClassNextOffset == 0, "just checking");
      }
      for (int i = 0; i < length; i += InnerClassAttributeOffset.innerClassNextOffset) {
        int ioff =
            innerClassList.getShortAt(i + InnerClassAttributeOffset.innerClassInnerClassInfoOffset);
        // 'ioff' can be zero.
        // refer to JVM spec. section 4.7.5.
        if (ioff != 0) {
          Oop iclassInfo = getConstants().getObjAt(ioff);
          Symbol innerName = null;
          if (iclassInfo instanceof Klass) {
            innerName = ((Klass) iclassInfo).getName();
          } else if (iclassInfo instanceof Symbol) {
            innerName = (Symbol) iclassInfo;
          } else {
            throw new RuntimeException("should not reach here");
          }

          Symbol myname = getName();
          int ooff =
              innerClassList.getShortAt(
                  i + InnerClassAttributeOffset.innerClassOuterClassInfoOffset);
          // for anonymous classes inner_name_index of InnerClasses
          // attribute is zero.
          int innerNameIndex =
              innerClassList.getShortAt(i + InnerClassAttributeOffset.innerClassInnerNameOffset);
          // if this is not a member (anonymous, local etc.), 'ooff' will be zero
          // refer to JVM spec. section 4.7.5.
          if (ooff == 0) {
            if (includeLocals) {
              // does it looks like my local class?
              if (innerName.equals(sym) && innerName.asString().startsWith(myname.asString())) {
                // exclude anonymous classes.
                return (innerNameIndex != 0);
              }
            }
          } else {
            Oop oclassInfo = getConstants().getObjAt(ooff);
            Symbol outerName = null;
            if (oclassInfo instanceof Klass) {
              outerName = ((Klass) oclassInfo).getName();
            } else if (oclassInfo instanceof Symbol) {
              outerName = (Symbol) oclassInfo;
            } else {
              throw new RuntimeException("should not reach here");
            }

            // include only if current class is outer class.
            if (outerName.equals(myname) && innerName.equals(sym)) {
              return true;
            }
          }
        }
      } // for inner classes
      return false;
    } else {
      return false;
    }
  }
Esempio n. 30
0
  public void rewrite() {
    int bytecode = Bytecodes._illegal;
    int hotspotcode = Bytecodes._illegal;
    int len = 0;

    for (int bci = 0; bci < code.length; ) {
      hotspotcode = Bytecodes.codeAt(method, bci);
      bytecode = Bytecodes.javaCode(hotspotcode);

      if (Assert.ASSERTS_ENABLED) {
        int code_from_buffer = 0xFF & code[bci];
        Assert.that(
            code_from_buffer == hotspotcode || code_from_buffer == Bytecodes._breakpoint,
            "Unexpected bytecode found in method bytecode buffer!");
      }

      // update the code buffer hotspot specific bytecode with the jvm bytecode
      code[bci] = (byte) (0xFF & bytecode);

      short cpoolIndex = 0;
      switch (bytecode) {
          // bytecodes with ConstantPoolCache index
        case Bytecodes._getstatic:
        case Bytecodes._putstatic:
        case Bytecodes._getfield:
        case Bytecodes._putfield:
        case Bytecodes._invokevirtual:
        case Bytecodes._invokespecial:
        case Bytecodes._invokestatic:
        case Bytecodes._invokeinterface:
          {
            cpoolIndex = getConstantPoolIndex(bci + 1);
            writeShort(code, bci + 1, cpoolIndex);
            break;
          }
      }

      len = Bytecodes.lengthFor(bytecode);
      if (len <= 0) len = Bytecodes.lengthAt(method, bci);

      if (DEBUG) {
        String operand = "";
        switch (len) {
          case 2:
            operand += code[bci + 1];
            break;
          case 3:
            operand += (cpoolIndex != 0) ? cpoolIndex : method.getBytecodeShortArg(bci + 1);
            break;
          case 5:
            operand += method.getBytecodeIntArg(bci + 1);
            break;
        }

        // the operand following # is not quite like javap output.
        // in particular, for goto & goto_w, the operand is PC relative
        // offset for jump. Javap adds relative offset with current PC
        // to give absolute bci to jump to.

        String message = "\t\t" + bci + " " + Bytecodes.name(bytecode);
        if (hotspotcode != bytecode) message += " [" + Bytecodes.name(hotspotcode) + "]";
        if (operand != "") message += " #" + operand;

        if (DEBUG) debugMessage(message);
      }

      bci += len;
    }
  }