use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.
the class NativeBootImage method markFunctionRelocationSite.
private static void markFunctionRelocationSite(final ProgbitsSectionImpl sectionImpl, final int offset, final RelocatableBuffer.Info info) {
assert info.getTargetObject() instanceof CFunctionPointer : "Wrong type for FunctionPointer relocation: " + info.getTargetObject().toString();
final int functionPointerRelocationSize = 8;
assert info.getRelocationSize() == functionPointerRelocationSize : "Function relocation: " + info.getRelocationSize() + " should be " + functionPointerRelocationSize + " bytes.";
// References to functions are via relocations to the symbol for the function.
HostedMethod method = ((MethodPointer) info.getTargetObject()).getMethod();
// A reference to a method. Mark the relocation site using the symbol name.
sectionImpl.markRelocationSite(offset, functionPointerRelocationSize, RelocationKind.DIRECT, localSymbolNameForMethod(method), false, 0L);
}
use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.
the class RelocatableBuffer method targetObjectClassification.
protected static String targetObjectClassification(final Object targetObject) {
final StringBuilder result = new StringBuilder();
if (targetObject == null) {
result.append("null");
} else {
if (targetObject instanceof CFunctionPointer) {
result.append("pointer to function");
if (targetObject instanceof MethodPointer) {
final MethodPointer mp = (MethodPointer) targetObject;
final HostedMethod hm = mp.getMethod();
result.append(" name: ");
result.append(hm.getName());
}
} else {
result.append("pointer to data");
}
}
return result.toString();
}
use of org.graalvm.nativeimage.c.function.CFunctionPointer in project graal by oracle.
the class UniverseBuilder method buildHubs.
private void buildHubs() {
ReferenceMapEncoder referenceMapEncoder = new ReferenceMapEncoder();
Map<HostedType, ReferenceMapEncoder.Input> referenceMaps = new HashMap<>();
for (HostedType type : hUniverse.orderedTypes) {
ReferenceMapEncoder.Input referenceMap = createReferenceMap(type);
referenceMaps.put(type, referenceMap);
referenceMapEncoder.add(referenceMap);
}
ImageSingletons.lookup(DynamicHubSupport.class).setData(referenceMapEncoder.encodeAll(null));
ObjectLayout ol = ConfigurationValues.getObjectLayout();
for (HostedType type : hUniverse.orderedTypes) {
int layoutHelper;
int monitorOffset = 0;
int hashCodeOffset = 0;
if (type.isInstanceClass()) {
HostedInstanceClass instanceClass = (HostedInstanceClass) type;
if (instanceClass.isAbstract()) {
layoutHelper = LayoutEncoding.forAbstract();
} else if (HybridLayout.isHybrid(type)) {
HybridLayout<?> hybridLayout = new HybridLayout<>(instanceClass, ol);
JavaKind kind = hybridLayout.getArrayElementKind();
layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, hybridLayout.getArrayBaseOffset(), ol.getArrayIndexShift(kind), ol.getAlignment());
} else {
layoutHelper = LayoutEncoding.forInstance(ConfigurationValues.getObjectLayout().alignUp(instanceClass.getInstanceSize()));
}
monitorOffset = instanceClass.getMonitorFieldOffset();
hashCodeOffset = instanceClass.getHashCodeFieldOffset();
} else if (type.isArray()) {
JavaKind kind = type.getComponentType().getStorageKind();
layoutHelper = LayoutEncoding.forArray(kind == JavaKind.Object, ol.getArrayBaseOffset(kind), ol.getArrayIndexShift(kind), ol.getAlignment());
hashCodeOffset = ol.getArrayHashCodeOffset();
} else if (type.isInterface()) {
layoutHelper = LayoutEncoding.forInterface();
} else if (type.isPrimitive()) {
layoutHelper = LayoutEncoding.forPrimitive();
} else {
throw shouldNotReachHere();
}
/*
* The vtable entry values are available only after the code cache layout is fixed, so
* leave them 0.
*/
CFunctionPointer[] vtable = new CFunctionPointer[type.vtable.length];
for (int idx = 0; idx < type.vtable.length; idx++) {
/*
* We install a CodePointer in the vtable; when generating relocation info, we will
* know these point into .text
*/
vtable[idx] = MethodPointer.factory(type.vtable[idx]);
}
// pointer maps in Dynamic Hub
ReferenceMapEncoder.Input referenceMap = referenceMaps.get(type);
assert referenceMap != null;
long referenceMapIndex = referenceMapEncoder.lookupEncoding(referenceMap);
DynamicHub hub = type.getHub();
hub.setData(layoutHelper, type.getTypeID(), monitorOffset, hashCodeOffset, type.getAssignableFromMatches(), type.instanceOfBits, vtable, referenceMapIndex, type.isInstantiated());
}
}
Aggregations