Mercurial > hg > graal-jvmci-8
changeset 21252:39ee26e85256
Use boxed cache in HotSpotConstantpool instead of synchronization
author | Stefan Anzinger <stefan.anzinger@oracle.com> |
---|---|
date | Tue, 05 May 2015 17:30:47 +0200 |
parents | e11eb6ec180e |
children | cf5f6a69d013 |
files | graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java |
diffstat | 1 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Mon May 04 23:15:42 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Tue May 05 17:30:47 2015 +0200 @@ -115,13 +115,23 @@ } } + private static class LookupTypeCacheElement { + int lastCpi = Integer.MIN_VALUE; + JavaType javaType; + + public LookupTypeCacheElement(int lastCpi, JavaType javaType) { + super(); + this.lastCpi = lastCpi; + this.javaType = javaType; + } + } + /** * Reference to the C++ ConstantPool object. */ private final long metaspaceConstantPool; private final Object[] cache; - private ResolvedJavaType lastType; - private int lastTypeCpi = Integer.MIN_VALUE; + private volatile LookupTypeCacheElement lastLookupType; public HotSpotConstantPool(long metaspaceConstantPool) { this.metaspaceConstantPool = metaspaceConstantPool; @@ -489,22 +499,15 @@ @Override public JavaType lookupType(int cpi, int opcode) { - if (cpi == this.lastTypeCpi) { - synchronized (this) { - if (cpi == this.lastTypeCpi) { - return this.lastType; - } - } + final LookupTypeCacheElement elem = this.lastLookupType; + if (elem != null && elem.lastCpi == cpi) { + return elem.javaType; + } else { + final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, cpi); + JavaType result = getJavaType(metaspacePointer); + this.lastLookupType = new LookupTypeCacheElement(cpi, result); + return result; } - final long metaspacePointer = runtime().getCompilerToVM().lookupKlassInPool(metaspaceConstantPool, cpi); - JavaType result = getJavaType(metaspacePointer); - if (result instanceof ResolvedJavaType) { - synchronized (this) { - this.lastType = (ResolvedJavaType) result; - this.lastTypeCpi = cpi; - } - } - return result; } @Override