Mercurial > hg > truffle
changeset 21376:739d9d9bd2fc
Allow closing of invocation plugin registry to prevent future modifications
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 14 May 2015 16:00:20 -0700 |
parents | fef56da8474e |
children | 6f2ff1bccbf1 |
files | graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java |
diffstat | 2 files changed, 44 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Thu May 14 15:59:14 2015 -0700 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/InvocationPlugins.java Thu May 14 16:00:20 2015 -0700 @@ -227,6 +227,14 @@ } /** + * Disallows new registrations of new plugins, and creates the internal tables for method + * lookup. + */ + public void closeRegistration() { + plugins.createEntries(); + } + + /** * Gets the invocation plugins {@linkplain #lookupInvocation(ResolvedJavaMethod) searched} * before searching in this object. */
--- a/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java Thu May 14 15:59:14 2015 -0700 +++ b/graal/com.oracle.graal.graphbuilderconf/src/com/oracle/graal/graphbuilderconf/MethodIdMap.java Thu May 14 16:00:20 2015 -0700 @@ -199,38 +199,7 @@ public V get(MethodIdHolder method) { if (entries == null) { - // 'assignIds' synchronizes on a global lock which ensures thread safe - // allocation of identifiers across all MethodIdHolder objects - MethodIdHolder.assignIds(new Consumer<MethodIdAllocator>() { - - public void accept(MethodIdAllocator idAllocator) { - if (entries == null) { - if (registrations.isEmpty()) { - entries = allocateEntries(0); - } else { - int max = Integer.MIN_VALUE; - for (MethodKey<V> methodKey : registrations) { - MethodIdHolder m = methodKey.resolve(metaAccess); - int id = idAllocator.assignId(m); - if (id < minId) { - minId = id; - } - if (id > max) { - max = id; - } - methodKey.id = id; - } - - int length = (max - minId) + 1; - entries = allocateEntries(length); - for (MethodKey<V> m : registrations) { - int index = m.id - minId; - entries[index] = m.value; - } - } - } - } - }); + createEntries(); } int id = method.getMethodId(); @@ -238,6 +207,41 @@ return index >= 0 && index < entries.length ? entries[index] : null; } + public void createEntries() { + // 'assignIds' synchronizes on a global lock which ensures thread safe + // allocation of identifiers across all MethodIdHolder objects + MethodIdHolder.assignIds(new Consumer<MethodIdAllocator>() { + + public void accept(MethodIdAllocator idAllocator) { + if (entries == null) { + if (registrations.isEmpty()) { + entries = allocateEntries(0); + } else { + int max = Integer.MIN_VALUE; + for (MethodKey<V> methodKey : registrations) { + MethodIdHolder m = methodKey.resolve(metaAccess); + int id = idAllocator.assignId(m); + if (id < minId) { + minId = id; + } + if (id > max) { + max = id; + } + methodKey.id = id; + } + + int length = (max - minId) + 1; + entries = allocateEntries(length); + for (MethodKey<V> m : registrations) { + int index = m.id - minId; + entries[index] = m.value; + } + } + } + } + }); + } + @Override public String toString() { return registrations.stream().map(MethodKey::toString).collect(Collectors.joining(", "));