public static String toString(UnmodifiableEconomicMap<OptionKey<?>, Object> values) { Comparator<OptionKey<?>> comparator = new Comparator<OptionKey<?>>() { @Override public int compare(OptionKey<?> o1, OptionKey<?> o2) { return o1.getName().compareTo(o2.getName()); } }; SortedMap<OptionKey<?>, Object> sorted = new TreeMap<>(comparator); UnmodifiableMapCursor<OptionKey<?>, Object> cursor = values.getEntries(); while (cursor.advance()) { sorted.put(cursor.getKey(), decodeNull(cursor.getValue())); } return sorted.toString(); }
/** * Returns the value to which {@code key} is mapped, or {@code defaultValue} if this map * contains no mapping for {@code key}. * * @since 1.0 */ default V get(K key, V defaultValue) { V v = get(key); if (v == null) { return defaultValue; } return v; }
private EconomicMapImpl(Equivalence strategy, UnmodifiableEconomicMap<K, V> other, boolean isSet) { this(strategy, isSet); if (!initFrom(other)) { init(other.size()); putAll(other); } }
/** * Updates this object with the key/value pairs in {@code values}. * * @see #UNSET_KEY */ public void update(UnmodifiableEconomicMap<OptionKey<?>, Object> values) { if (values.isEmpty()) { return; } UnmodifiableEconomicMap<OptionKey<?>, Object> expect; EconomicMap<OptionKey<?>, Object> newMap; do { expect = v.get(); newMap = EconomicMap.create(Equivalence.IDENTITY, expect); UnmodifiableMapCursor<OptionKey<?>, Object> cursor = values.getEntries(); while (cursor.advance()) { OptionKey<?> key = cursor.getKey(); Object value = cursor.getValue(); if (value == UNSET_KEY) { newMap.removeKey(key); } else { key.update(newMap, value); // Need to do the null encoding here as `key.update()` doesn't do it newMap.put(key, encodeNull(value)); } } } while (!v.compareAndSet(expect, newMap)); }
SnippetTemplate template = template(arraycopy, args); UnmodifiableEconomicMap<Node, Node> replacements = template.instantiate(providers.getMetaAccess(), arraycopy, SnippetTemplate.DEFAULT_REPLACER, args, false); for (Node originalNode : replacements.getKeys()) { if (originalNode instanceof InvokeNode) { InvokeNode invoke = (InvokeNode) replacements.get(originalNode); assert invoke.asNode().graph() == graph; CallTargetNode call = invoke.callTarget(); throw new GraalError("unexpected invoke with exception %s in snippet", originalNode); } else if (originalNode instanceof ArrayCopyWithSlowPathNode) { ArrayCopyWithSlowPathNode slowPath = (ArrayCopyWithSlowPathNode) replacements.get(originalNode); assert arraycopy.stateAfter() != null : arraycopy; assert slowPath.stateAfter() == arraycopy.stateAfter();
protected boolean containsKey(OptionKey<?> key) { return values.containsKey(key); }
/** * Ensure that all states are either {@link BytecodeFrame#INVALID_FRAMESTATE_BCI} or one of * {@link BytecodeFrame#AFTER_BCI} or {@link BytecodeFrame#BEFORE_BCI}. Mixing of before and * after isn't allowed. */ private static boolean checkContainsOnlyInvalidOrAfterFrameState(UnmodifiableEconomicMap<Node, Node> duplicates) { int okBci = BytecodeFrame.INVALID_FRAMESTATE_BCI; for (Node node : duplicates.getValues()) { if (node instanceof FrameState) { FrameState frameState = (FrameState) node; if (frameState.bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { continue; } if (frameState.bci == BytecodeFrame.AFTER_BCI || frameState.bci == BytecodeFrame.BEFORE_BCI) { if (okBci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { okBci = frameState.bci; } else { assert okBci == frameState.bci : node.toString(Verbosity.Debugger); } } else { assert false : node.toString(Verbosity.Debugger); } } } return true; }
/** * Determines if this object currently contains any plugins (in any state of registration). If * this object has any {@link #defer(Runnable) deferred registrations}, it is assumed that * executing them will result in at least one plugin being registered. */ public boolean isEmpty() { if (parent != null && !parent.isEmpty()) { return false; } UnmodifiableEconomicMap<ResolvedJavaMethod, InvocationPlugin> resolvedRegs = resolvedRegistrations; if (resolvedRegs != null) { if (!resolvedRegs.isEmpty()) { return false; } } List<Runnable> deferred = deferredRegistrations; if (deferred != null) { if (!deferred.isEmpty()) { return false; } } for (LateClassPlugins late = lateRegistrations; late != null; late = late.next) { if (!late.bindings.isEmpty()) { return false; } } return registrations.size() == 0; }
@Override protected boolean containsKey(OptionKey<?> key) { return v.get().containsKey(key); }
/** * Copies all of the mappings from {@code other} to this map. * * @since 1.0 */ default void putAll(UnmodifiableEconomicMap<? extends K, ? extends V> other) { UnmodifiableMapCursor<? extends K, ? extends V> entry = other.getEntries(); while (entry.advance()) { put(entry.getKey(), entry.getValue()); } }
/** * Returns the value to which {@code key} is mapped, or {@code defaultValue} if this map * contains no mapping for {@code key}. * * @since 1.0 */ default V get(K key, V defaultValue) { V v = get(key); if (v == null) { return defaultValue; } return v; }
private EconomicMapImpl(Equivalence strategy, UnmodifiableEconomicMap<K, V> other, boolean isSet) { this(strategy, isSet); if (!initFrom(other)) { init(other.size()); putAll(other); } }
/** * Copies all of the mappings from {@code other} to this map. * * @since 1.0 */ default void putAll(UnmodifiableEconomicMap<? extends K, ? extends V> other) { UnmodifiableMapCursor<? extends K, ? extends V> entry = other.getEntries(); while (entry.advance()) { put(entry.getKey(), entry.getValue()); } }
@SuppressWarnings("unchecked") protected static <T> T get(UnmodifiableEconomicMap<OptionKey<?>, Object> values, OptionKey<T> key) { Object value = values.get(key); if (value == null) { return key.getDefaultValue(); } return (T) decodeNull(value); }
@Override protected Map<String, Object> createInitialOptions() { Map<String, Object> res = new HashMap<>(); UnmodifiableMapCursor<OptionKey<?>, Object> optionValues = RuntimeOptionValues.singleton().getMap().getEntries(); while (optionValues.advance()) { final OptionKey<?> key = optionValues.getKey(); Object value = optionValues.getValue(); if (value == null) { value = key.getDefaultValue(); } res.put(key.getName(), value); } return res; }
private void copyTree(Callsite site, Callsite replacementSite, UnmodifiableEconomicMap<Node, Node> replacements, EconomicMap<Callsite, Callsite> mapping) { mapping.put(replacementSite, site); site.target = replacementSite.target; site.decisions.addAll(replacementSite.decisions); site.invoke = replacementSite.invoke != null && replacementSite.invoke.isAlive() ? (Invokable) replacements.get(replacementSite.invoke.asFixedNode()) : null; for (Callsite replacementChild : replacementSite.children) { Callsite child = new Callsite(site, null); site.children.add(child); copyTree(child, replacementChild, replacements, mapping); } }
@Override public Map<String, Object> createInitialOptions() { final UnmodifiableMapCursor<OptionKey<?>, Object> optionValues = getOptions(OptionValues.class).getMap().getEntries(); Map<String, Object> res = new HashMap<>(); while (optionValues.advance()) { final OptionKey<?> key = optionValues.getKey(); Object value = optionValues.getValue(); if (value == null) { value = key.getDefaultValue(); } res.put(key.getName(), value); } return res; }
private void updateStamps(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) { for (ValueNode node : placeholderStampedNodes) { ValueNode dup = (ValueNode) duplicates.get(node); Stamp replaceeStamp = replacee.stamp(NodeView.DEFAULT); if (node instanceof Placeholder) { Placeholder placeholderDup = (Placeholder) dup; placeholderDup.makeReplacement(replaceeStamp); } else { dup.setStamp(replaceeStamp); } } for (ParameterNode paramNode : snippet.getNodes(ParameterNode.TYPE)) { for (Node usage : paramNode.usages()) { Node usageDup = duplicates.get(usage); propagateStamp(usageDup); } } }
protected static void initMap(EconomicMap<OptionKey<?>, Object> map, UnmodifiableEconomicMap<OptionKey<?>, Object> values) { UnmodifiableMapCursor<OptionKey<?>, Object> cursor = values.getEntries(); while (cursor.advance()) { map.put(cursor.getKey(), encodeNull(cursor.getValue())); } }
@Override public MemoryNode getLastLocationAccess(LocationIdentity locationIdentity) { MemoryMapNode memoryMap = returnNode.getMemoryMap(); assert memoryMap != null : "no memory map stored for this snippet graph (snippet doesn't have a ReturnNode?)"; MemoryNode lastLocationAccess = memoryMap.getLastLocationAccess(locationIdentity); assert lastLocationAccess != null : locationIdentity; if (lastLocationAccess == memoryAnchor) { return super.getLastLocationAccess(locationIdentity); } else { return (MemoryNode) duplicates.get(ValueNodeUtil.asNode(lastLocationAccess)); } }