コード例 #1
0
ファイル: NEW.java プロジェクト: nunomachado/cortex-tool
  public Instruction execute(SystemState ss, KernelState ks, ThreadInfo ti) {
    Heap heap = ti.getHeap();
    ClassInfo ci;

    try {
      ci = ClassInfo.getResolvedClassInfo(cname);

    } catch (NoClassInfoException cx) {
      // can be any inherited class or required interface
      return ti.createAndThrowException("java.lang.NoClassDefFoundError", cx.getMessage());
    }

    if (!ci.isRegistered()) {
      ci.registerClass(ti);
    }

    // since this is a NEW, we also have to pushClinit
    if (!ci.isInitialized()) {
      if (ci.initializeClass(ti)) {
        return ti.getPC(); // reexecute this instruction once we return from the clinits
      }
    }

    if (heap.isOutOfMemory()) { // simulate OutOfMemoryError
      return ti.createAndThrowException(
          "java.lang.OutOfMemoryError", "trying to allocate new " + cname);
    }

    int objRef = heap.newObject(ci, ti);
    newObjRef = objRef;

    // pushes the return value onto the stack
    ti.push(objRef, true);

    ss.checkGC(); // has to happen after we push the new object ref

    return getNext(ti);
  }