[vmkit-commits] [vmkit] r180359 - Removed use of VirtualTable in EscapeAnalysis.
Peter Senna Tschudin
peter.senna at gmail.com
Thu Apr 25 10:03:21 PDT 2013
Author: peter.senna
Date: Thu Apr 25 12:01:18 2013
New Revision: 180359
URL: http://llvm.org/viewvc/llvm-project?rev=180359&view=rev
Log:
Removed use of VirtualTable in EscapeAnalysis.
(cherry picked from commit 0b177bb74d1264307125be37f86f69d160f8103a)
Modified:
vmkit/trunk/include/vmkit/GC.h
vmkit/trunk/include/vmkit/VirtualMachine.h
vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp
vmkit/trunk/lib/j3/VMCore/Jnjvm.h
vmkit/trunk/lib/vmkit/Compiler/EscapeAnalysis.cpp
vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
Modified: vmkit/trunk/include/vmkit/GC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/vmkit/GC.h?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/include/vmkit/GC.h (original)
+++ vmkit/trunk/include/vmkit/GC.h Thu Apr 25 12:01:18 2013
@@ -14,7 +14,6 @@
#include <stdint.h>
#include "vmkit/System.h"
-class VirtualTable;
class gc;
class gcHeader {
@@ -28,17 +27,6 @@ public:
class gcRoot {
private:
- /// getVirtualTable - Returns the virtual table of this object.
- ///
-// VirtualTable* getVirtualTable() const {
-// return ((VirtualTable**)(this))[0];
-// }
-
- /// setVirtualTable - Sets the virtual table of this object.
- ///
-// void setVirtualTable(VirtualTable* VT) {
-// ((VirtualTable**)(this))[0] = VT;
-// }
public:
virtual ~gcRoot() {}
virtual void tracer(word_t closure) {}
Modified: vmkit/trunk/include/vmkit/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/vmkit/VirtualMachine.h?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/include/vmkit/VirtualMachine.h (original)
+++ vmkit/trunk/include/vmkit/VirtualMachine.h Thu Apr 25 12:01:18 2013
@@ -218,6 +218,11 @@ public:
///
virtual const char* getObjectTypeName(gc* object) { return "An object"; }
+ /// hasFinalizer - Determine if the specified type has a finalizer.
+ ///
+ virtual int hasFinalizer(void* type) { return 1; }
+
+
/// rendezvous - The rendezvous implementation for garbage collection.
///
CooperativeCollectionRV rendezvous;
Modified: vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/j3/VMCore/Jnjvm.cpp Thu Apr 25 12:01:18 2013
@@ -1498,3 +1498,9 @@ void Jnjvm::printMethod(vmkit::FrameInfo
fprintf(stderr, "\n");
}
+
+int Jnjvm::hasFinalizer(void* type) {
+ JavaVirtualTable* vt = (JavaVirtualTable*)type;
+ return vt->hasDestructor();
+}
+
Modified: vmkit/trunk/lib/j3/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/j3/VMCore/Jnjvm.h?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/lib/j3/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/j3/VMCore/Jnjvm.h Thu Apr 25 12:01:18 2013
@@ -142,6 +142,7 @@ private:
virtual void clearObjectReferent(gc* ref);
virtual gc** getObjectReferentPtr(gc* _obj);
virtual void setObjectReferent(gc* _obj, gc* val);
+ virtual int hasFinalizer(void* type);
/// CreateError - Creates a Java object of the specified exception class
/// and calling its <init> function.
Modified: vmkit/trunk/lib/vmkit/Compiler/EscapeAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/vmkit/Compiler/EscapeAnalysis.cpp?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/lib/vmkit/Compiler/EscapeAnalysis.cpp (original)
+++ vmkit/trunk/lib/vmkit/Compiler/EscapeAnalysis.cpp Thu Apr 25 12:01:18 2013
@@ -24,6 +24,9 @@
#include <map>
#include "vmkit/GC.h"
+#include "vmkit/Thread.h"
+#include "vmkit/VirtualMachine.h"
+#include <stdio.h>
using namespace llvm;
@@ -53,13 +56,14 @@ namespace {
bool EscapeAnalysis::runOnFunction(Function& F) {
bool Changed = false;
Function* Allocator = F.getParent()->getFunction("gcmalloc");
- if (!Allocator) return Changed;
+ Function* hasFinalizer = F.getParent()->getFunction("hasFinalizer");
+ if (!Allocator || !hasFinalizer) return Changed;
LoopInfo* LI = &getAnalysis<LoopInfo>();
- for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) {
+ for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; BI++) {
BasicBlock *Cur = BI;
-
+
// Get the parent loop if there is one. If the allocation happens in a loop
// we must make sure that the allocated value is not used outside of
// the loop. If the allocation does not escape and it is only used inside
@@ -115,23 +119,23 @@ bool EscapeAnalysis::runOnFunction(Funct
static bool escapes(Value* Ins, std::map<Instruction*, bool>& visited) {
- for (Value::use_iterator I = Ins->use_begin(), E = Ins->use_end();
+ for (Value::use_iterator I = Ins->use_begin(), E = Ins->use_end();
I != E; ++I) {
if (Instruction* II = dyn_cast<Instruction>(*I)) {
- if (II->getOpcode() == Instruction::Call ||
+ if (II->getOpcode() == Instruction::Call ||
II->getOpcode() == Instruction::Invoke) {
-
+
CallSite CS(II);
if (!CS.onlyReadsMemory()) return true;
-
+
CallSite::arg_iterator B = CS.arg_begin(), E = CS.arg_end();
for (CallSite::arg_iterator A = B; A != E; ++A) {
- if (A->get() == Ins &&
+ if (A->get() == Ins &&
!CS.paramHasAttr(A - B + 1, Attributes::NoCapture)) {
return true;
}
}
-
+
// We must also consider the value returned by the function.
if (II->getType() == Ins->getType()) {
if (escapes(II, visited)) return true;
@@ -176,12 +180,12 @@ bool EscapeAnalysis::processMalloc(Instr
ConstantInt* CI = dyn_cast<ConstantInt>(Size);
bool hasFinalizer = true;
-
+
if (CI) {
if (ConstantExpr* CE = dyn_cast<ConstantExpr>(VT)) {
if (ConstantInt* C = dyn_cast<ConstantInt>(CE->getOperand(0))) {
- VirtualTable* Table = (VirtualTable*)C->getZExtValue();
- hasFinalizer = (((void**)Table)[0] != 0);
+ void* type = (void*)C->getZExtValue();
+ hasFinalizer = vmkit::Thread::get()->MyVM->hasFinalizer(type);
} else {
GlobalVariable* GV = dyn_cast<GlobalVariable>(CE->getOperand(0));
if (GV->hasInitializer()) {
@@ -204,7 +208,7 @@ bool EscapeAnalysis::processMalloc(Instr
Alloc->eraseFromParent();
return true;
}
-
+
uint64_t NSize = CI->getZExtValue();
// If the class has a finalize method, do not stack allocate the object.
if (NSize < pageSize && !hasFinalizer) {
Modified: vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp?rev=180359&r1=180358&r2=180359&view=diff
==============================================================================
--- vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp (original)
+++ vmkit/trunk/mmtk/mmtk-alloc/Selected.cpp Thu Apr 25 12:01:18 2013
@@ -92,6 +92,11 @@ extern "C" void* gcmalloc(uint32_t sz, v
}
*/
+extern "C" int hasFinalizer(void* type) {
+ return vmkit::Thread::get()->MyVM->hasFinalizer(type);
+}
+
+
extern "C" void* gcmalloc(uint32_t sz, void* type) {
gc* res = 0;
llvm_gcroot(res, 0);
More information about the vmkit-commits
mailing list