/**
   * 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;
  }
 // 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 #3
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 #4
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;
 }
 // "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 #6
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 #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;
 }
 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;
 }
 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;
 }
 /** 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;
 }
Example #11
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
 }
  /** 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;
  }
Example #16
0
 public long getInvocationCounter() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(!VM.getVM().isCore(), "must not be used in core build");
   }
   return invocationCounter.getValue(this);
 }
 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 #18
0
 public int getRegisterNumber() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.IN_REGISTER, "wrong Where");
   }
   return getOffset();
 }
Example #19
0
 public int getStackOffset() {
   if (Assert.ASSERTS_ENABLED) {
     Assert.that(getWhere() == Where.ON_STACK, "wrong Where");
   }
   return getOffset() * (int) VM.getVM().getIntSize();
 }
  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;
    }
  }