use of org.graalvm.compiler.word.Word in project graal by oracle.
the class NewInstanceStub method edenAllocate.
/**
* Attempts to allocate a chunk of memory from Eden space.
*
* @param sizeInBytes the size of the chunk to allocate
* @param log specifies if logging is enabled
* @return the allocated chunk or {@link WordFactory#zero()} if allocation fails
*/
public static Word edenAllocate(Word sizeInBytes, boolean log) {
final long heapTopRawAddress = GraalHotSpotVMConfigNode.heapTopAddress();
final long heapEndRawAddress = GraalHotSpotVMConfigNode.heapEndAddress();
Word heapTopAddress = WordFactory.unsigned(heapTopRawAddress);
Word heapEndAddress = WordFactory.unsigned(heapEndRawAddress);
while (true) {
Word heapTop = heapTopAddress.readWord(0, HEAP_TOP_LOCATION);
Word newHeapTop = heapTop.add(sizeInBytes);
if (newHeapTop.belowOrEqual(heapTop)) {
return WordFactory.zero();
}
Word heapEnd = heapEndAddress.readWord(0, HEAP_END_LOCATION);
if (newHeapTop.aboveThan(heapEnd)) {
return WordFactory.zero();
}
if (heapTopAddress.logicCompareAndSwapWord(0, heapTop, newHeapTop, HEAP_TOP_LOCATION)) {
return heapTop;
}
}
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class NewInstanceStub method allocate.
private static Word allocate(Word thread, int size) {
Word top = readTlabTop(thread);
Word end = readTlabEnd(thread);
Word newTop = top.add(size);
/*
* this check might lead to problems if the TLAB is within 16GB of the address space end
* (checked in c++ code)
*/
if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) {
writeTlabTop(thread, newTop);
return top;
}
return WordFactory.zero();
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class StubUtil method verifyObject.
/**
* Verifies that a given object value is well formed if {@code -XX:+VerifyOops} is enabled.
*/
public static Object verifyObject(Object object) {
if (verifyOops(INJECTED_VMCONFIG)) {
Word verifyOopCounter = WordFactory.unsigned(verifyOopCounterAddress(INJECTED_VMCONFIG));
verifyOopCounter.writeInt(0, verifyOopCounter.readInt(0) + 1);
Pointer oop = Word.objectToTrackedPointer(object);
if (object != null) {
GuardingNode anchorNode = SnippetAnchorNode.anchor();
// make sure object is 'reasonable'
if (!oop.and(WordFactory.unsigned(verifyOopMask(INJECTED_VMCONFIG))).equal(WordFactory.unsigned(verifyOopBits(INJECTED_VMCONFIG)))) {
fatal("oop not in heap: %p", oop.rawValue());
}
KlassPointer klass = loadHubIntrinsic(PiNode.piCastNonNull(object, anchorNode));
if (klass.isNull()) {
fatal("klass for oop %p is null", oop.rawValue());
}
}
}
return object;
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class WordTest method cast.
@Snippet
public static long cast(long input) {
WordBase base = WordFactory.signed(input);
UnsignedWord unsigned = (UnsignedWord) base;
Pointer pointer = (Pointer) unsigned;
Word word = (Word) pointer;
return word.rawValue();
}
use of org.graalvm.compiler.word.Word in project graal by oracle.
the class MonitorSnippets method tryEnterInflated.
private static boolean tryEnterInflated(Object object, Word lock, Word mark, Register threadRegister, boolean trace, OptionValues options, Counters counters) {
// write non-zero value to lock slot
lock.writeWord(lockDisplacedMarkOffset(INJECTED_VMCONFIG), lock, DISPLACED_MARK_WORD_LOCATION);
// mark is a pointer to the ObjectMonitor + monitorMask
Word monitor = mark.subtract(monitorMask(INJECTED_VMCONFIG));
int ownerOffset = objectMonitorOwnerOffset(INJECTED_VMCONFIG);
Word owner = monitor.readWord(ownerOffset, OBJECT_MONITOR_OWNER_LOCATION);
if (probability(FREQUENT_PROBABILITY, owner.equal(0))) {
// it appears unlocked (owner == 0)
if (probability(FREQUENT_PROBABILITY, monitor.logicCompareAndSwapWord(ownerOffset, owner, registerAsWord(threadRegister), OBJECT_MONITOR_OWNER_LOCATION))) {
// success
traceObject(trace, "+lock{inflated:cas}", object, true, options);
counters.inflatedCas.inc();
return true;
} else {
traceObject(trace, "+lock{stub:inflated:failed-cas}", object, true, options);
counters.inflatedFailedCas.inc();
}
} else {
traceObject(trace, "+lock{stub:inflated:owned}", object, true, options);
counters.inflatedOwned.inc();
}
return false;
}
Aggregations