Esempio n. 1
0
 private static long headerSize(BasicType type) {
   if (Universe.elementTypeShouldBeAligned(type)) {
     return alignObjectSize(headerSizeInBytes()) / VM.getVM().getHeapWordSize();
   } else {
     return headerSizeInBytes() / VM.getVM().getHeapWordSize();
   }
 }
 private void initOtherId() {
   VM vm = getOtherVm();
   vm.invoke(
       new CacheSerializableRunnable("Connect") {
         public void run2() throws CacheException {
           getCache();
         }
       });
   this.otherId = (DistributedMember) vm.invoke(ProxyDUnitTest.class, "getVMDistributedMember");
 }
Esempio n. 3
0
 private long lengthOffsetInBytes() {
   if (lengthOffsetInBytes != 0) {
     return lengthOffsetInBytes;
   }
   if (VM.getVM().isCompressedOopsEnabled()) {
     lengthOffsetInBytes = typeSize - VM.getVM().getIntSize();
   } else {
     lengthOffsetInBytes = typeSize;
   }
   return lengthOffsetInBytes;
 }
 private void doCreateOtherVm() {
   VM vm = getOtherVm();
   vm.invoke(
       new CacheSerializableRunnable("create root") {
         public void run2() throws CacheException {
           AttributesFactory af = new AttributesFactory();
           af.setDataPolicy(DataPolicy.REPLICATE);
           af.setScope(Scope.DISTRIBUTED_ACK);
           createRootRegion("ProxyDUnitTest", af.create());
         }
       });
 }
Esempio n. 5
0
 private static long headerSizeInBytes() {
   if (headerSize != 0) {
     return headerSize;
   }
   if (VM.getVM().isCompressedOopsEnabled()) {
     headerSize = typeSize;
   } else {
     headerSize =
         VM.getVM().alignUp(typeSize + VM.getVM().getIntSize(), VM.getVM().getHeapWordSize());
   }
   return headerSize;
 }
  /** 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. 7
0
 public static CGGradient create(CGColorSpace space, float[] components, float[] locations) {
   if (space == null) {
     throw new NullPointerException("space");
   }
   if (components == null) {
     throw new NullPointerException("components");
   }
   return create(
       space,
       VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(components)),
       locations != null
           ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations))
           : 0,
       locations != null ? locations.length : 0);
 }
 // "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. 9
0
 private static void initialize(TypeDataBase db) {
   if (VM.getVM().isServerCompiler()) {
     Type type = db.lookupType("Matcher");
     Field f = type.getField("_regEncode");
     matcherRegEncodeAddr = f.getStaticFieldAddress();
   }
 }
Esempio n. 10
0
 public void replaceRegion(
     @ByVal MTLRegion region,
     @MachineSizedUInt long level,
     byte[] pixelBytes,
     @MachineSizedUInt long bytesPerRow) {
   replaceRegion(region, level, VM.getArrayValuesAddress(pixelBytes), bytesPerRow);
 }
Esempio n. 11
0
  /**
   * Logic to select the appropriate guarding mechanism for the edge from caller to callee according
   * to the controlling {@link OPT_Options}. If we are using IG_CODE_PATCH, then this method also
   * records the required dependency. Precondition: lock on {@link VM_Class#OptCLDepManager} is
   * held.
   *
   * @param caller The caller method
   * @param callee The callee method
   * @param codePatchSupported Can we use code patching at this call site?
   */
  private byte chooseGuard(
      VM_Method caller,
      VM_Method singleImpl,
      VM_Method callee,
      OPT_CompilationState state,
      boolean codePatchSupported) {
    byte guard = state.getOptions().INLINING_GUARD;
    if (codePatchSupported) {
      if (VM.VerifyAssertions && VM.runningVM) {
        VM._assert(VM_Lock.owns(VM_Class.OptCLDepManager));
      }
      if (guard == OPT_Options.IG_CODE_PATCH) {
        if (OPT_ClassLoadingDependencyManager.TRACE || OPT_ClassLoadingDependencyManager.DEBUG) {
          VM_Class.OptCLDepManager.report(
              "CODE PATCH: Inlined " + singleImpl + " into " + caller + "\n");
        }
        VM_Class.OptCLDepManager.addNotOverriddenDependency(callee, state.getCompiledMethod());
      }
    } else if (guard == OPT_Options.IG_CODE_PATCH) {
      guard = OPT_Options.IG_METHOD_TEST;
    }

    if (guard == OPT_Options.IG_METHOD_TEST && singleImpl.getDeclaringClass().isFinal()) {
      // class test is more efficient and just as effective
      guard = OPT_Options.IG_CLASS_TEST;
    }
    return guard;
  }
Esempio n. 12
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;
 }
Esempio n. 13
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. 14
0
 public long getLongAt(long index) {
   int oneHalf = getHandle().getJIntAt(indexOffset(index + 1));
   int otherHalf = getHandle().getJIntAt(indexOffset(index));
   // buildLongFromIntsPD accepts higher address value, lower address value
   // in that order.
   return VM.getVM().buildLongFromIntsPD(oneHalf, otherHalf);
 }
Esempio n. 15
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);
  }
Esempio n. 16
0
 /*</constructors>*/
 public NSOutputStream(byte[] bytes) {
   super((SkipInit) null);
   if (bytes == null) {
     throw new NullPointerException("bytes");
   }
   initObject(init(VM.getArrayValuesAddress(bytes), bytes.length));
 }
Esempio n. 17
0
 public long write(byte[] bytes, int offset, int length) {
   NSMutableData.checkOffsetAndCount(bytes.length, offset, length);
   if (length == 0) {
     return 0;
   }
   return write(VM.getArrayValuesAddress(bytes) + offset, length);
 }
Esempio n. 18
0
 private long getElementSize() {
   if (elementSize != 0) {
     return elementSize;
   } else {
     elementSize = VM.getVM().getOopSize();
   }
   return elementSize;
 }
Esempio n. 19
0
 static {
   VM.registerVMInitializedObserver(
       new Observer() {
         public void update(Observable o, Object data) {
           initialize(VM.getVM().getTypeDataBase());
         }
       });
 }
Esempio n. 20
0
 public byte[] getBytes(
     int length,
     @MachineSizedUInt long bytesPerRow,
     @ByVal MTLRegion region,
     @MachineSizedUInt long level) {
   byte[] bytes = new byte[length];
   getBytes(VM.getArrayValuesAddress(bytes), bytesPerRow, region, level);
   return bytes;
 }
Esempio n. 21
0
 /** Convenience routine taking Strings; lookup is done in SymbolTable. */
 public Method findMethod(String name, String sig) {
   SymbolTable syms = VM.getVM().getSymbolTable();
   Symbol nameSym = syms.probe(name);
   Symbol sigSym = syms.probe(sig);
   if (nameSym == null || sigSym == null) {
     return null;
   }
   return findMethod(nameSym, sigSym);
 }
Esempio n. 22
0
 /**
  * @param offset
  * @param length
  * @return
  * @throws NSErrorException
  */
 public byte[] getBytes(int offset, int length) throws NSErrorException {
   byte[] bytes = new byte[length];
   NSError.NSErrorPtr err = new NSError.NSErrorPtr();
   getBytes(VM.getArrayValuesAddress(bytes), offset, length, err);
   if (err.get() != null) {
     throw new NSErrorException(err.get());
   }
   return bytes;
 }
Esempio n. 23
0
  private static void initialize(TypeDataBase db) {
    Type type = db.lookupType("oopDesc");

    if (VM.getVM().isCompressedOopsEnabled()) {
      klassField = type.getNarrowOopField("_metadata._compressed_klass");
    } else {
      klassField = type.getOopField("_metadata._klass");
    }
  }
Esempio n. 24
0
  public ThreadProxy getThreadProxy(Address addr) {
    // Addr is the address of the JavaThread.
    // Fetch the OSThread (for now and for simplicity, not making a
    // separate "OSThread" class in this package)
    Address osThreadAddr = osThreadField.getValue(addr);
    // Get the address of the _thread_id from the OSThread
    Address threadIdAddr = osThreadAddr.addOffsetTo(osThreadThreadIDField.getOffset());

    JVMDebugger debugger = VM.getVM().getDebugger();
    return debugger.getThreadForIdentifierAddress(threadIdAddr);
  }
Esempio n. 25
0
 private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) {
   if (colors == null) {
     throw new NullPointerException("colors");
   }
   try (CFArray colorsArray = CFArray.create(colors)) {
     return create(
         space,
         colorsArray,
         locations != null
             ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations))
             : 0);
   }
 }
Esempio n. 26
0
 /**
  * Compute node congruence over the value number graph.
  *
  * <p>Algorithm: Muchnick pp. 348-355
  *
  * <p>Note: the Muchnick algorithm is buggy. In particular, it does not put all needed congruence
  * classes on the worklist.
  *
  * <p>Two nodes in the value graph are congruent if one of the following holds:
  *
  * <ul>
  *   <li>they are the same node
  *   <li>their labels are identical constants
  *   <li>they have the same operators and their operands are congruent
  * </ul>
  *
  * <p>Optimistic algorithm:
  *
  * <ul>
  *   <li>Initially assume all nodes with the same label are congruent
  *   <li>start a work list with all congruence classes that have multiple operands
  *   <li>choose a congruence class from the worklist. partition its elements into new congruence
  *       classes if we can discover that they are not congruent.
  *   <li>Add any newly created congruence classes to the work list.
  *   <li>(Here's the step Muchnick omits:) For each class C which has a dependence on any of the
  *       newly created congruence classes, add C to the work list
  *   <li>repeat until work list is empty
  * </ul>
  *
  * <p>The following method breaks Muchnick's algorithm, which will assign m and n the same value
  * number. Muchnick's problem is that it does not put the congruence class for 'int_mul' back on
  * the worklist when we discover, for example, that i is not congruent to k
  *
  * <pre>
  *   public int foo(int a, int b, int c, int d, int e, int f, int g, int h) {
  *      int i = a+b;
  *      int j = c+d;
  *      int k = e+f;
  *      int l = g+h;
  *      int m = i * j;
  *      int n = k * l;
  *      int o = m/n;
  *      return o;
  *   }
  *  </pre>
  */
 public void globalValueNumber() {
   valueGraph = new OPT_ValueGraph(ir);
   if (DEBUG) VM.sysWrite(valueGraph.toString());
   // initialize the congurence classes
   initialize();
   // initialize the work list
   initializeWorkList();
   // drain the work list
   while (!workList.empty()) {
     OPT_GVCongruenceClass partition = (OPT_GVCongruenceClass) workList.pop();
     partitionClass(partition);
   }
   // all done
   if (DEBUG) printValueNumbers();
 }
Esempio n. 27
0
 private static CGGradient create(CGColorSpace space, CGColor[] colors, Object locations) {
   if (colors == null) {
     throw new NullPointerException("colors");
   }
   try (CFMutableArray colorsArray =
       CFMutableArray.createMutable(null, colors.length, CoreFoundation.TypeArrayCallBacks())) {
     for (CGColor c : colors) {
       colorsArray.appendValue(Struct.toStruct(VoidPtr.class, c.getHandle()));
     }
     return create(
         space,
         colorsArray,
         locations != null
             ? VM.getArrayValuesAddress(CoreGraphics.toMachineSizedFloatArray(locations))
             : 0);
   }
 }
Esempio n. 28
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);
  }
Esempio n. 29
0
 public static boolean oopLooksValid(OopHandle oop) {
   if (oop == null) {
     return false;
   }
   if (!VM.getVM().getUniverse().isIn(oop)) {
     return false;
   }
   try {
     for (int i = 0; i < 4; ++i) {
       OopHandle next = klassField.getValue(oop);
       if (next == null) {
         return false;
       }
       if (next.equals(oop)) {
         return true;
       }
       oop = next;
     }
     return false;
   } catch (AddressException e) {
     return false;
   }
 }
Esempio n. 30
0
 // Creates new field from index in fields TypeArray
 private Field newField(int index) {
   TypeArray fields = getFields();
   short signatureIndex = fields.getShortAt(index + SIGNATURE_INDEX_OFFSET);
   FieldType type = new FieldType((Symbol) getConstants().getObjAt(signatureIndex));
   if (type.isOop()) {
     if (VM.getVM().isCompressedOopsEnabled()) {
       return new NarrowOopField(this, index);
     } else {
       return new OopField(this, index);
     }
   }
   if (type.isByte()) {
     return new ByteField(this, index);
   }
   if (type.isChar()) {
     return new CharField(this, index);
   }
   if (type.isDouble()) {
     return new DoubleField(this, index);
   }
   if (type.isFloat()) {
     return new FloatField(this, index);
   }
   if (type.isInt()) {
     return new IntField(this, index);
   }
   if (type.isLong()) {
     return new LongField(this, index);
   }
   if (type.isShort()) {
     return new ShortField(this, index);
   }
   if (type.isBoolean()) {
     return new BooleanField(this, index);
   }
   throw new RuntimeException("Illegal field type at index " + index);
 }