use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class LLVMX86_64VaListStorage method shift.
/**
* This is the implementation of the {@code va_arg} instruction.
*/
@SuppressWarnings("static-method")
@ExportMessage
Object shift(Type type, @SuppressWarnings("unused") Frame frame, @CachedLibrary(limit = "1") LLVMManagedReadLibrary readLib, @CachedLibrary(limit = "1") LLVMManagedWriteLibrary writeLib, @Cached BranchProfile regAreaProfile, @Cached("createBinaryProfile()") ConditionProfile isNativizedProfile) {
int regSaveOffs = 0;
int regSaveStep = 0;
int regSaveLimit = 0;
boolean lookIntoRegSaveArea = true;
VarArgArea varArgArea = getVarArgArea(type);
switch(varArgArea) {
case GP_AREA:
regSaveOffs = X86_64BitVarArgs.GP_OFFSET;
regSaveStep = X86_64BitVarArgs.GP_STEP;
regSaveLimit = X86_64BitVarArgs.GP_LIMIT;
break;
case FP_AREA:
regSaveOffs = X86_64BitVarArgs.FP_OFFSET;
regSaveStep = X86_64BitVarArgs.FP_STEP;
regSaveLimit = X86_64BitVarArgs.FP_LIMIT;
break;
case OVERFLOW_AREA:
lookIntoRegSaveArea = false;
break;
}
if (lookIntoRegSaveArea) {
regAreaProfile.enter();
int offs = readLib.readI32(this, regSaveOffs);
if (offs < regSaveLimit) {
writeLib.writeI32(this, regSaveOffs, offs + regSaveStep);
long n = this.regSaveArea.offsetToIndex(offs);
int i = (int) ((n << 32) >> 32);
return this.regSaveArea.args[i];
}
}
// overflow area
if (isNativizedProfile.profile(isNativized())) {
// Synchronize the managed current argument pointer from the native overflow area
this.overflowArgArea.setOffset(getArgPtrFromNativePtr(this, readLib));
Object currentArg = this.overflowArgArea.getCurrentArg();
// Shift the managed current argument pointer
this.overflowArgArea.shift(1);
// Update the new native current argument pointer from the managed one
long shiftOffs = this.overflowArgArea.getOffset();
LLVMPointer shiftedOverflowAreaPtr = overflowArgAreaBaseNativePtr.increment(shiftOffs);
writeLib.writePointer(this, X86_64BitVarArgs.OVERFLOW_ARG_AREA, shiftedOverflowAreaPtr);
return currentArg;
} else {
Object currentArg = this.overflowArgArea.getCurrentArg();
this.overflowArgArea.shift(1);
return currentArg;
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method writeBufferLong.
@ExportMessage
public void writeBufferLong(ByteOrder order, long index, long value, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws InvalidBufferOffsetException, UnsupportedMessageException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Long.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
if (isPEFriendlyBuffer(buffer)) {
buffer.putLong((int) index, value);
} else {
putBufferLongBoundary(buffer, (int) index, value);
}
buffer.order(originalOrder);
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Long.BYTES);
} catch (ReadOnlyBufferException e) {
error.enter();
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method isMetaInstance.
@ExportMessage
@TruffleBoundary
boolean isMetaInstance(Object other, @CachedLibrary("this") InteropLibrary library, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
if (isClass()) {
Class<?> c = asClass();
HostLanguage language = context != null ? HostLanguage.get(library) : null;
if (HostObject.isInstance(language, other)) {
Object otherHostObj = HostObject.valueOf(language, other);
if (otherHostObj == null) {
return false;
} else {
return c.isInstance(otherHostObj);
}
} else if (HostProxy.isProxyGuestObject(language, other)) {
Proxy otherHost = HostProxy.toProxyHostObject(language, other);
return c.isInstance(otherHost);
} else {
boolean canConvert = HostToTypeNode.canConvert(other, c, c, HostToTypeNode.allowsImplementation(context, c), context, HostToTypeNode.LOWEST, InteropLibrary.getFactory().getUncached(other), HostTargetMappingNode.getUncached());
return canConvert;
}
} else {
error.enter();
throw UnsupportedMessageException.create();
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method invokeMember.
@ExportMessage
Object invokeMember(String name, Object[] args, @Shared("lookupMethod") @Cached LookupMethodNode lookupMethod, @Shared("hostExecute") @Cached HostExecuteNode executeMethod, @Shared("lookupField") @Cached LookupFieldNode lookupField, @Shared("readField") @Cached ReadFieldNode readField, @CachedLibrary(limit = "5") InteropLibrary fieldValues, @Shared("error") @Cached BranchProfile error) throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
if (isNull()) {
error.enter();
throw UnsupportedMessageException.create();
}
boolean isStatic = isStaticClass();
Class<?> lookupClass = getLookupClass();
// (1) look for a method; if found, invoke it on obj.
HostMethodDesc foundMethod = lookupMethod.execute(this, lookupClass, name, isStatic);
if (foundMethod != null) {
return executeMethod.execute(foundMethod, obj, args, context);
}
// (2) look for a field; if found, read its value and if that IsExecutable, Execute it.
HostFieldDesc foundField = lookupField.execute(this, lookupClass, name, isStatic);
if (foundField != null) {
Object fieldValue = readField.execute(foundField, this);
if (fieldValues.isExecutable(fieldValue)) {
return fieldValues.execute(fieldValue, args);
}
}
error.enter();
throw UnknownIdentifierException.create(name);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class HostObject method readBufferFloat.
@ExportMessage
public float readBufferFloat(ByteOrder order, long index, @Shared("isBuffer") @Cached IsBufferNode isBuffer, @Shared("error") @Cached BranchProfile error, @Shared("classProfile") @Cached("createClassProfile()") ValueProfile classProfile) throws UnsupportedMessageException, InvalidBufferOffsetException {
if (!isBuffer.execute(this)) {
error.enter();
throw UnsupportedMessageException.create();
}
if (index < 0 || Integer.MAX_VALUE < index) {
error.enter();
throw InvalidBufferOffsetException.create(index, Float.BYTES);
}
try {
final ByteBuffer buffer = (ByteBuffer) classProfile.profile(obj);
final ByteOrder originalOrder = buffer.order();
buffer.order(order);
final float result = isPEFriendlyBuffer(buffer) ? buffer.getFloat((int) index) : getBufferFloatBoundary(buffer, (int) index);
buffer.order(originalOrder);
return result;
} catch (IndexOutOfBoundsException e) {
error.enter();
throw InvalidBufferOffsetException.create(index, Float.BYTES);
}
}
Aggregations