public static long saturate(long v, Kind kind) { long max = kind.getMaxValue(); if (v > max) { return max; } long min = kind.getMinValue(); if (v < min) { return min; } return v; }
private static Stamp narrowingKindConvertion(IntegerStamp fromStamp, Kind toKind) { long mask = fromStamp.mask() & IntegerStamp.defaultMask(toKind); long lowerBound = saturate(fromStamp.lowerBound(), toKind); long upperBound = saturate(fromStamp.upperBound(), toKind); if (fromStamp.lowerBound() < toKind.getMinValue()) { upperBound = toKind.getMaxValue(); } if (fromStamp.upperBound() > toKind.getMaxValue()) { lowerBound = toKind.getMinValue(); } return StampFactory.forInteger(toKind.getStackKind(), lowerBound, upperBound, mask); }
/** * Ensure that the frame state is formatted as expected by the JVM, with null or Illegal in the * slot following a double word item. This should really be checked in FrameState itself but * because of Word type rewriting and alternative backends that can't be done. */ public boolean validateFormat() { if (caller() != null) { caller().validateFormat(); } for (int i = 0; i < numLocals + numStack; i++) { if (values[i] != null) { Kind kind = values[i].getKind(); if (kind.needsTwoSlots()) { assert values.length > i + 1 : String.format("missing second word %s", this); assert values[i + 1] == null || values[i + 1].getKind() == Kind.Illegal : this; } } } return true; }
public static Stamp negate(Stamp stamp) { Kind kind = stamp.kind(); if (stamp instanceof IntegerStamp) { IntegerStamp integerStamp = (IntegerStamp) stamp; if (integerStamp.lowerBound() != kind.getMinValue()) { // TODO(ls) check if the mask calculation is correct... return new IntegerStamp( kind, -integerStamp.upperBound(), -integerStamp.lowerBound(), IntegerStamp.defaultMask(kind) & (integerStamp.mask() | -integerStamp.mask())); } } return StampFactory.forKind(kind); }
private synchronized void save() { myDir.mkdirs(); Properties props = new Properties(); props.setProperty(KIND_KEY, myKind.toString()); props.setProperty(ID_KEY, myRepositoryId); props.setProperty(PATH_OR_URL_KEY, myRepositoryPathOrUrl); props.setProperty(INDEX_VERSION_KEY, CURRENT_VERSION); if (myUpdateTimestamp != null) props.setProperty(TIMESTAMP_KEY, String.valueOf(myUpdateTimestamp)); if (myDataDirName != null) props.setProperty(DATA_DIR_NAME_KEY, myDataDirName); if (myFailureMessage != null) props.setProperty(FAILURE_MESSAGE_KEY, myFailureMessage); try { FileOutputStream s = new FileOutputStream(new File(myDir, INDEX_INFO_FILE)); try { props.store(s, null); } finally { s.close(); } } catch (IOException e) { MavenLog.LOG.warn(e); } }
public MavenIndex(MavenIndexerWrapper indexer, File dir, IndexListener listener) throws MavenIndexException { myIndexer = indexer; myDir = dir; myListener = listener; Properties props = new Properties(); try { FileInputStream s = new FileInputStream(new File(dir, INDEX_INFO_FILE)); try { props.load(s); } finally { s.close(); } } catch (IOException e) { throw new MavenIndexException("Cannot read " + INDEX_INFO_FILE + " file", e); } if (!CURRENT_VERSION.equals(props.getProperty(INDEX_VERSION_KEY))) { throw new MavenIndexException("Incompatible index version, needs to be updated: " + dir); } myKind = Kind.valueOf(props.getProperty(KIND_KEY)); myRepositoryId = props.getProperty(ID_KEY); myRepositoryPathOrUrl = normalizePathOrUrl(props.getProperty(PATH_OR_URL_KEY)); try { String timestamp = props.getProperty(TIMESTAMP_KEY); if (timestamp != null) myUpdateTimestamp = Long.parseLong(timestamp); } catch (Exception ignored) { } myDataDirName = props.getProperty(DATA_DIR_NAME_KEY); myFailureMessage = props.getProperty(FAILURE_MESSAGE_KEY); if (!getUpdateDir().exists()) { myUpdateTimestamp = null; } open(); }