Beispiel #1
0
  public void forEachObject(Object[] args) {
    boolean subtypes = true;
    Klass kls = null;
    Callable func = null;
    switch (args.length) {
      case 3:
        {
          Object b = args[2];
          if (b != null && b instanceof Boolean) {
            subtypes = ((Boolean) b).booleanValue();
          }
        }
      case 2:
        {
          Object k = args[1];
          if (k == null) return;
          if (k instanceof JSJavaKlass) {
            kls = ((JSJavaKlass) k).getKlass();
          } else if (k instanceof String) {
            kls = SystemDictionaryHelper.findInstanceKlass((String) k);
            if (kls == null) return;
          }
        }
      case 1:
        {
          Object f = args[0];
          if (f != null && f instanceof Callable) {
            func = (Callable) f;
          } else {
            // unknown target - just return
            return;
          }
        }
        break;

      default:
        return;
    }

    final Callable finalFunc = func;
    HeapVisitor visitor =
        new DefaultHeapVisitor() {
          public boolean doObj(Oop oop) {
            JSJavaObject jo = factory.newJSJavaObject(oop);
            if (jo != null) {
              try {
                finalFunc.call(new Object[] {jo});
              } catch (ScriptException exp) {
                throw new RuntimeException(exp);
              }
            }
            return false;
          }
        };
    ObjectHeap heap = VM.getVM().getObjectHeap();
    if (kls == null) {
      kls = SystemDictionaryHelper.findInstanceKlass("java.lang.Object");
    }
    heap.iterateObjectsOfKlass(visitor, kls, subtypes);
  }
Beispiel #2
0
  private void iterateOops(
      final InstanceKlass ik, final ObjectVisitor visitor, boolean includeSubtypes) {
    ObjectHeap oh = VM.getVM().getObjectHeap();
    oh.iterateObjectsOfKlass(
        new HeapVisitor() {
          boolean filterExists;

          public void prologue(long usedSize) {
            filterExists = getScriptEngine().get("filter") != null;
          }

          public boolean doObj(Oop obj) {
            dispatchObject(obj, visitor, filterExists);
            return false;
          }

          public void epilogue() {}
        },
        ik,
        includeSubtypes);
  }
 private void markAndTraverse(OopHandle handle) {
   try {
     markAndTraverse(heap.newOop(handle));
   } catch (AddressException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: AddressException at 0x"
             + Long.toHexString(e.getAddress())
             + " while traversing oop at "
             + handle);
   } catch (UnknownOopException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: UnknownOopException for " + "oop at " + handle);
   }
 }