[vmkit-commits] [vmkit] r199100 - Small API for header access.
Gael Thomas
gael.thomas at lip6.fr
Mon Jan 13 03:51:10 PST 2014
Author: gthomas
Date: Mon Jan 13 05:51:10 2014
New Revision: 199100
URL: http://llvm.org/viewvc/llvm-project?rev=199100&view=rev
Log:
Small API for header access.
Modified:
vmkit/branches/mcjit/include/j3/j3object.h
vmkit/branches/mcjit/lib/j3/vm/j3object.cc
Modified: vmkit/branches/mcjit/include/j3/j3object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/j3/j3object.h?rev=199100&r1=199099&r2=199100&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/j3/j3object.h (original)
+++ vmkit/branches/mcjit/include/j3/j3object.h Mon Jan 13 05:51:10 2014
@@ -23,6 +23,7 @@ namespace j3 {
class J3FixedPoint;
class J3Method;
class J3Monitor;
+ class J3LockRecord;
// see: Cliff Click and John Rose. 2002. Fast subtype checking in the HotSpot JVM.
// In Proceedings of the 2002 joint ACM-ISCOPE conference on Java Grande (JGI '02). ACM, New York, NY, USA, 96-107.
@@ -103,9 +104,15 @@ namespace j3 {
J3Object(); /* never directly allocate an object */
bool isLockOwner();
- J3Monitor* monitor();
+ J3Monitor* inflate();
uint32_t hashCode();
+ static bool isUnlocked(uintptr_t header) { return (header & 7) == 1; }
+ static bool isInflated(uintptr_t header) { return (header & 3) == 2; }
+ static bool isStackLocked(uintptr_t header) { return !(header & 3); }
+ static J3LockRecord* asLockRecord(uintptr_t header) { return (J3LockRecord*)header; }
+ static J3Monitor* asMonitor(uintptr_t header) { return (J3Monitor*)(header & ~3); }
+
static void monitorEnter(J3Object* obj);
static void monitorExit(J3Object* obj);
Modified: vmkit/branches/mcjit/lib/j3/vm/j3object.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3object.cc?rev=199100&r1=199099&r2=199100&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3object.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3object.cc Mon Jan 13 05:51:10 2014
@@ -304,7 +304,7 @@ uint32_t J3Object::hashCode() {
while(1) {
uintptr_t header = _header;
- if((header & 0x7) == 1) { /* not locked, not inflated */
+ if(isUnlocked(header)) { /* not locked, not inflated */
uint32_t res = header >> 8;
if(res)
return res;
@@ -316,7 +316,7 @@ uint32_t J3Object::hashCode() {
return res;
} else {
/* if stack locked, force the inflation because I can not modify the stack of the owner */
- J3Monitor* m = monitor();
+ J3Monitor* m = inflate();
header = m->header;
@@ -333,24 +333,12 @@ uint32_t J3Object::hashCode() {
}
}
-bool J3Object::isLockOwner() {
- J3Thread* self = J3Thread::get();
- uintptr_t header = _header;
-
- if((header & 0x3) == 2) /* inflated */
- return ((J3Monitor*)(header & -2))->isOwner(self);
- else
- return !(header & 3) && (J3Thread*)(header & J3Thread::getThreadMask()) == self;
-}
-
-J3Monitor* J3Object::monitor() {
- uintptr_t header = _header;
-
+J3Monitor* J3Object::inflate() {
while(1) {
uintptr_t header = _header;
- if((header & 0x3) == 2) { /* already inflated */
- J3Monitor* res = (J3Monitor*)(header & -2);
+ if(isInflated(header)) { /* already inflated */
+ J3Monitor* res = asMonitor(header);
if(res)
return res;
else
@@ -359,16 +347,17 @@ J3Monitor* J3Object::monitor() {
/* ok, I'm the boss */
J3Monitor* monitor = J3Thread::get()->vm()->monitorManager.allocate();
- if(!(header & 3)) { /* stack locked */
- J3LockRecord* record = (J3LockRecord*)header;
+ if(isStackLocked(header)) { /* stack locked */
+ J3LockRecord* record = asLockRecord(header);
/* I can read record->header because, in the worst case, the owner is blocked in the sched_yield loop */
/* however, I can not read lockCount because the owner is maybe playing with this value */
monitor->prepare(this, record->header, record);
} else { /* not locked at all */
- if((header & 7) != 1)
+ if(!isUnlocked(header))
J3::internalError("should not happen");
monitor->prepare(this, header, 0);
}
+
_header = (uintptr_t)monitor | 2;
return monitor;
@@ -376,6 +365,16 @@ J3Monitor* J3Object::monitor() {
}
}
+bool J3Object::isLockOwner() {
+ J3Thread* self = J3Thread::get();
+ uintptr_t header = _header;
+
+ if(isInflated(header)) /* inflated */
+ return asMonitor(header)->isOwner(self);
+ else
+ return !isUnlocked(header) && (J3Thread*)(header & J3Thread::getThreadMask()) == self;
+}
+
/*
* --- J3ArrayObject ---
*/
@@ -391,7 +390,7 @@ J3Object* J3ArrayObject::doNew(J3ArrayCl
* J3ObjectHandle
*/
void J3ObjectHandle::wait() {
- obj()->monitor()->wait();
+ obj()->inflate()->wait();
}
bool J3ObjectHandle::isLockOwner() {
More information about the vmkit-commits
mailing list