< prev index next >
src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java
Print this page
rev 12604 : 8173912: [JVMCI] fix memory overhead of JVMCI
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -74,10 +74,16 @@
private HotSpotMethodData methodData;
private byte[] code;
private Executable toJavaCache;
/**
+ * Only 30% of {@link HotSpotResolvedJavaMethodImpl}s have their name accessed so compute it
+ * lazily and cache it.
+ */
+ private String nameCache;
+
+ /**
* Gets the holder of a HotSpot metaspace method native object.
*
* @param metaspaceMethod a metaspace Method object
* @return the {@link ResolvedJavaType} corresponding to the holder of the
* {@code metaspaceMethod}
@@ -104,12 +110,10 @@
HotSpotResolvedObjectTypeImpl holder = getHolder(metaspaceMethod);
return holder.createMethod(metaspaceMethod);
}
HotSpotResolvedJavaMethodImpl(HotSpotResolvedObjectTypeImpl holder, long metaspaceMethod) {
- // It would be too much work to get the method name here so we fill it in later.
- super(null);
this.metaspaceMethod = metaspaceMethod;
this.holder = holder;
HotSpotVMConfig config = config();
final long constMethod = getConstMethod();
@@ -124,13 +128,10 @@
this.constantPool = holder.getConstantPool();
} else {
this.constantPool = compilerToVM().getConstantPool(this);
}
- final int nameIndex = UNSAFE.getChar(constMethod + config.constMethodNameIndexOffset);
- this.name = constantPool.lookupUtf8(nameIndex);
-
final int signatureIndex = UNSAFE.getChar(constMethod + config.constMethodSignatureIndexOffset);
this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex);
}
/**
@@ -145,10 +146,19 @@
assert metaspaceMethod != 0;
return UNSAFE.getAddress(metaspaceMethod + config().methodConstMethodOffset);
}
@Override
+ public String getName() {
+ if (nameCache == null) {
+ final int nameIndex = UNSAFE.getChar(getConstMethod() + config().constMethodNameIndexOffset);
+ nameCache = constantPool.lookupUtf8(nameIndex);
+ }
+ return nameCache;
+ }
+
+ @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof HotSpotResolvedJavaMethodImpl) {
@@ -324,16 +334,28 @@
return compilerToVM().methodIsIgnoredBySecurityStackWalk(this);
}
@Override
public boolean isClassInitializer() {
- return "<clinit>".equals(name) && isStatic();
+ if (isStatic()) {
+ final int nameIndex = UNSAFE.getChar(getConstMethod() + config().constMethodNameIndexOffset);
+ long nameSymbol = constantPool.getEntryAt(nameIndex);
+ long clinitSymbol = config().symbolClinit;
+ return nameSymbol == clinitSymbol;
+ }
+ return false;
}
@Override
public boolean isConstructor() {
- return "<init>".equals(name) && !isStatic();
+ if (!isStatic()) {
+ final int nameIndex = UNSAFE.getChar(getConstMethod() + config().constMethodNameIndexOffset);
+ long nameSymbol = constantPool.getEntryAt(nameIndex);
+ long initSymbol = config().symbolInit;
+ return nameSymbol == initSymbol;
+ }
+ return false;
}
@Override
public int getMaxLocals() {
if (isAbstract() || isNative()) {
@@ -470,11 +492,11 @@
}
@Override
public Annotation[][] getParameterAnnotations() {
Executable javaMethod = toJava();
- return javaMethod == null ? null : javaMethod.getParameterAnnotations();
+ return javaMethod == null ? new Annotation[signature.getParameterCount(false)][0] : javaMethod.getParameterAnnotations();
}
@Override
public Annotation[] getAnnotations() {
Executable javaMethod = toJava();
@@ -511,13 +533,10 @@
public boolean isVarArgs() {
return (VARARGS & getModifiers()) != 0;
}
public boolean isDefault() {
- if (isConstructor()) {
- return false;
- }
// Copied from java.lang.Method.isDefault()
int mask = Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC;
return ((getModifiers() & mask) == Modifier.PUBLIC) && getDeclaringClass().isInterface();
}
@@ -560,11 +579,11 @@
if (isConstructor()) {
result = holder.mirror().getDeclaredConstructor(parameterTypes);
} else {
// Do not use Method.getDeclaredMethod() as it can return a bridge method
// when this.isBridge() is false and vice versa.
- result = searchMethods(holder.mirror().getDeclaredMethods(), name, returnType, parameterTypes);
+ result = searchMethods(holder.mirror().getDeclaredMethods(), getName(), returnType, parameterTypes);
}
toJavaCache = result;
return result;
} catch (NoSuchMethodException | NoClassDefFoundError e) {
return null;
< prev index next >