/**
   * 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;
  }
 // "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();
 }
Example #3
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;
 }
Example #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();
  }
Example #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;
 }
 // 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;
 }
Example #7
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;
 }
Example #8
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;
 }
 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;
 }
 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;
 }
  Instruction decodeFloatInstruction(
      int instruction,
      SPARCRegister rs1,
      SPARCRegister rs2,
      SPARCRegister rd,
      SPARCInstructionFactory factory) {
    if (Assert.ASSERTS_ENABLED)
      Assert.that(rs2.isFloat() && rd.isFloat(), "rs2, rd have to be float registers");

    return factory.newFP2RegisterInstruction(
        name, opf, (SPARCFloatRegister) rs2, (SPARCFloatRegister) rd);
  }
Example #12
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 = 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
 }
 /** 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;
    }
  }
  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);
 }
  // 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);
     }
   }
 }
Example #19
0
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check getfield");
   }
 }
 public ConstantPoolCacheEntry getEntryAt(int i) {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(0 <= i && i < getLength(), "index out of bounds");
   }
   return new ConstantPoolCacheEntry(this, i);
 }
Example #21
0
 public long getInvocationCounter() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(!VM.getVM().isCore(), "must not be used in core build");
   }
   return invocationCounter.getValue(this);
 }
Example #22
0
 public int getRegisterNumber() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.IN_REGISTER, "wrong Where");
   }
   return getOffset();
 }
Example #23
0
 public int getStackOffset() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.ON_STACK, "wrong Where");
   }
   return getOffset() * (int) VM.getVM().getIntSize();
 }
Example #24
0
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check fast_aaccess_0");
   }
 }
Example #25
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;
    }
  }
  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;
    }
  }
 public void verify() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(isValid(), "check bipush");
   }
 }