package com.oracle.svm.core.code;
import org.graalvm.nativeimage.c.function.CodePointer;
import org.graalvm.word.UnsignedWord;
import com.oracle.svm.core.annotate.Uninterruptible;
import com.oracle.svm.core.c.NonmovableArrays;
public final class UntetheredCodeInfoAccess {
private UntetheredCodeInfoAccess() {
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.")
public static Object getTetherUnsafe(UntetheredCodeInfo info) {
return getObjectFieldUnsafe(info, CodeInfoImpl.TETHER_OBJFIELD);
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static CodePointer getCodeStart(UntetheredCodeInfo info) {
return cast(info).getCodeStart();
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static CodePointer getCodeEnd(UntetheredCodeInfo info) {
CodeInfoImpl codeInfo = cast(info);
return (CodePointer) ((UnsignedWord) codeInfo.getCodeStart()).add(codeInfo.getCodeSize());
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static UnsignedWord getCodeSize(UntetheredCodeInfo info) {
return cast(info).getCodeSize();
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static int getTier(UntetheredCodeInfo info) {
return cast(info).getTier();
}
@SuppressWarnings("unchecked")
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static <T> T getObjectFieldUnsafe(UntetheredCodeInfo info, int index) {
return (T) NonmovableArrays.getObject(cast(info).getObjectFields(), index);
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static int getState(UntetheredCodeInfo info) {
return cast(info).getState();
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static boolean isAlive(UntetheredCodeInfo info) {
return CodeInfoAccess.isAliveState(cast(info).getState());
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
public static String getName(UntetheredCodeInfo info) {
return getObjectFieldUnsafe(info, CodeInfoImpl.NAME_OBJFIELD);
}
@Uninterruptible(reason = "Must prevent the GC from freeing the CodeInfo object.", callerMustBe = true)
private static CodeInfoImpl cast(UntetheredCodeInfo info) {
assert info.isNonNull();
return (CodeInfoImpl) info;
}
}