use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class InfoTreeBuilder method elementKind.
private ElementKind elementKind(Collection<AccessorInfo> accessorInfos) {
ElementKind overallKind = ElementKind.UNKNOWN;
AccessorInfo overallKindAccessor = null;
for (AccessorInfo accessorInfo : accessorInfos) {
ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
ElementKind newKind;
switch(accessorInfo.getAccessorKind()) {
case GETTER:
newKind = elementKind((ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass()));
break;
case SETTER:
newKind = elementKind((ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.valueParameterNumber(false), method.getDeclaringClass()));
break;
default:
continue;
}
if (overallKind == ElementKind.UNKNOWN) {
overallKind = newKind;
overallKindAccessor = accessorInfo;
} else if (overallKind != newKind) {
nativeLibs.addError("Accessor methods mix integer, floating point, and pointer kinds", overallKindAccessor.getAnnotatedElement(), method);
}
}
return overallKind;
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class InfoTreeBuilder method createRawStructInfo.
private void createRawStructInfo(ResolvedJavaType type) {
if (!validInterfaceDefinition(type, RawStructure.class)) {
return;
}
Map<String, List<AccessorInfo>> fieldAccessorInfos = new TreeMap<>();
List<AccessorInfo> structAccessorInfos = new ArrayList<>();
for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
String fieldName;
AccessorInfo accessorInfo;
RawField fieldAnnotation = getMethodAnnotation(method, RawField.class);
if (fieldAnnotation != null) {
if (method.getSignature().getReturnKind() == JavaKind.Void) {
accessorInfo = new AccessorInfo(method, AccessorKind.SETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
} else {
accessorInfo = new AccessorInfo(method, AccessorKind.GETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
}
fieldName = getStructFieldName(method, "", accessorInfo.getAccessorKind());
} else if (method.getSignature().getReturnType(method.getDeclaringClass()).equals(method.getDeclaringClass())) {
fieldName = null;
accessorInfo = new AccessorInfo(method, AccessorKind.ADDRESS, method.getSignature().getParameterCount(false) > 0, false, false);
} else {
nativeLibs.addError("Unexpected method without annotation", method);
continue;
}
if (accessorValid(accessorInfo)) {
if (fieldName == null) {
structAccessorInfos.add(accessorInfo);
} else {
Map<String, List<AccessorInfo>> map = fieldAccessorInfos;
List<AccessorInfo> accessorInfos = map.get(fieldName);
if (accessorInfos == null) {
accessorInfos = new ArrayList<>();
map.put(fieldName, accessorInfos);
}
accessorInfos.add(accessorInfo);
}
nativeLibs.registerElementInfo(method, accessorInfo);
}
}
String typeName = getStructName(type);
StructInfo structInfo = StructInfo.create(typeName, type);
structInfo.adoptChildren(structAccessorInfos);
for (Map.Entry<String, List<AccessorInfo>> entry : fieldAccessorInfos.entrySet()) {
StructFieldInfo fieldInfo = new StructFieldInfo(entry.getKey(), elementKind(entry.getValue()));
fieldInfo.adoptChildren(entry.getValue());
structInfo.adoptChild(fieldInfo);
}
nativeCodeInfo.adoptChild(structInfo);
nativeLibs.registerElementInfo(type, structInfo);
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class RestrictHeapAccessCalleesFeature method findAssertionConstructor.
/**
* Look up an AssertionError constructor.
*/
private static ResolvedJavaMethod findAssertionConstructor(DuringAnalysisAccess access, Class<?>... parameterTypes) {
try {
final Constructor<AssertionError> reflectiveConstructor = AssertionError.class.getConstructor(parameterTypes);
final ResolvedJavaMethod resolvedConstructor = ((DuringAnalysisAccessImpl) access).getMetaAccess().lookupJavaMethod(reflectiveConstructor);
return resolvedConstructor;
} catch (NoSuchMethodException | SecurityException ex) {
throw VMError.shouldNotReachHere("Should have found AssertionError constructor." + ex);
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class QueryResultParser method visitConstantInfo.
@Override
protected void visitConstantInfo(ConstantInfo constantInfo) {
TargetDescription target = nativeLibs.getTarget();
switch(constantInfo.getKind()) {
case INTEGER:
parseIntegerProperty(constantInfo.getSizeInfo());
parseSignedness(constantInfo.getSignednessInfo());
parseIntegerConstantValue(constantInfo.getValueInfo());
/*
* From the point of view of the C compiler, plain #define constants have the type
* int and therefore size 4. But sometimes we want to access such values as short or
* byte to avoid casts. Check the actual value of the constant, and if it fits the
* declared type of the constant, then change the actual size to the declared size.
*/
ResolvedJavaMethod method = (ResolvedJavaMethod) constantInfo.getAnnotatedElement();
ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
JavaKind returnKind = returnType.getJavaKind();
if (returnKind == JavaKind.Object) {
returnKind = target.wordJavaKind;
}
int declaredSize = target.arch.getPlatformKind(returnKind).getSizeInBytes();
int actualSize = constantInfo.getSizeInfo().getProperty();
if (declaredSize != actualSize) {
long value = (long) constantInfo.getValueInfo().getProperty();
if (value >= returnKind.getMinValue() && value <= returnKind.getMaxValue()) {
constantInfo.getSizeInfo().setProperty(declaredSize);
}
}
break;
case POINTER:
parseIntegerProperty(constantInfo.getSizeInfo());
parseIntegerConstantValue(constantInfo.getValueInfo());
break;
case FLOAT:
parseIntegerProperty(constantInfo.getSizeInfo());
parseFloatValue(constantInfo.getValueInfo());
break;
case STRING:
parseStringValue(constantInfo.getValueInfo());
break;
case BYTEARRAY:
parseByteArrayValue(constantInfo.getValueInfo());
break;
default:
throw shouldNotReachHere();
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class BytecodeParser method createStateAfterStartOfReplacementGraph.
/**
* Creates the frame state after the start node of a graph for an {@link IntrinsicContext
* intrinsic} that is the parse root (either for root compiling or for post-parse inlining).
*/
private FrameState createStateAfterStartOfReplacementGraph() {
assert parent == null;
assert frameState.getMethod().equals(intrinsicContext.getIntrinsicMethod());
assert bci() == 0;
assert frameState.stackSize() == 0;
FrameState stateAfterStart;
if (intrinsicContext.isPostParseInlined()) {
stateAfterStart = graph.add(new FrameState(BytecodeFrame.BEFORE_BCI));
} else {
ResolvedJavaMethod original = intrinsicContext.getOriginalMethod();
ValueNode[] locals;
if (original.getMaxLocals() == frameState.localsSize() || original.isNative()) {
locals = new ValueNode[original.getMaxLocals()];
for (int i = 0; i < locals.length; i++) {
ValueNode node = frameState.locals[i];
if (node == FrameState.TWO_SLOT_MARKER) {
node = null;
}
locals[i] = node;
}
} else {
locals = new ValueNode[original.getMaxLocals()];
int parameterCount = original.getSignature().getParameterCount(!original.isStatic());
for (int i = 0; i < parameterCount; i++) {
ValueNode param = frameState.locals[i];
if (param == FrameState.TWO_SLOT_MARKER) {
param = null;
}
locals[i] = param;
assert param == null || param instanceof ParameterNode || param.isConstant();
}
}
ValueNode[] stack = {};
int stackSize = 0;
ValueNode[] locks = {};
List<MonitorIdNode> monitorIds = Collections.emptyList();
stateAfterStart = graph.add(new FrameState(null, new ResolvedJavaMethodBytecode(original), 0, locals, stack, stackSize, locks, monitorIds, false, false));
}
return stateAfterStart;
}
Aggregations