[vmkit-commits] [vmkit] r83723 - in /vmkit/trunk/lib/N3: PNetLib/PNetLib.cpp VMCore/Assembly.cpp VMCore/Assembly.h VMCore/CLIJit.cpp VMCore/MSCorlib.inc VMCore/Reader.cpp VMCore/Reader.h VMCore/VirtualTables.cpp
Gael Thomas
gael.thomas at lip6.fr
Sat Oct 10 12:43:40 PDT 2009
Author: gthomas
Date: Sat Oct 10 14:43:39 2009
New Revision: 83723
URL: http://llvm.org/viewvc/llvm-project?rev=83723&view=rev
Log:
A N3 bytecode is now allocated with a BumpPtrAllocator.
Modified:
vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.cpp
vmkit/trunk/lib/N3/VMCore/Assembly.h
vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
vmkit/trunk/lib/N3/VMCore/MSCorlib.inc
vmkit/trunk/lib/N3/VMCore/Reader.cpp
vmkit/trunk/lib/N3/VMCore/Reader.h
vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp
Modified: vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp (original)
+++ vmkit/trunk/lib/N3/PNetLib/PNetLib.cpp Sat Oct 10 14:43:39 2009
@@ -960,7 +960,7 @@
extern "C" uint32 System_Reflection_ClrResourceStream_ResourceRead(Assembly* assembly, uint64 position, ArrayUInt8* buffer, uint32 offset, uint32 count) {
uint32 resRva = assembly->resRva;
- ArrayUInt8* bytes = assembly->bytes;
+ ByteCode* bytes = assembly->bytes;
Section* textSection = assembly->textSection;
uint32 section = 0;
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.cpp?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.cpp Sat Oct 10 14:43:39 2009
@@ -619,7 +619,7 @@
#define EXTRACT_SIZE(bitmask, index) \
(1 + (3 & (bitmask >> (index << 1))))
-void Table::readRow(uint32* result, uint32 row, ArrayUInt8* array) {
+void Table::readRow(uint32* result, uint32 row, ByteCode* array) {
uint32 rowOffset = offset + ((row - 1) * rowSize);
for (uint32 i = 0; i < count; ++i) {
uint32 size = EXTRACT_SIZE(sizeMask, i);
@@ -632,7 +632,7 @@
}
}
-uint32 Table::readIndexInRow(uint32 row, uint32 index, ArrayUInt8* array) {
+uint32 Table::readIndexInRow(uint32 row, uint32 index, ByteCode* array) {
uint32 indexOffset = offset + ((row - 1) * rowSize);
for (uint32 i = 0; i < index; ++i) {
indexOffset += EXTRACT_SIZE(sizeMask, i);
@@ -709,7 +709,7 @@
}
const ArrayUInt16* Assembly::readUTF16(N3* vm, uint32 len,
- ArrayUInt8* bytes, uint32 &offset) {
+ ByteCode* bytes, uint32 &offset) {
uint32 realLen = len >> 1;
uint16* buf = (uint16*)alloca(len);
uint32 i = 0;
@@ -726,7 +726,7 @@
}
const UTF8* Assembly::readUTF8(N3* vm, uint32 len,
- ArrayUInt8* bytes, uint32 &offset) {
+ ByteCode* bytes, uint32 &offset) {
uint16* buf = (uint16*)alloca(len * sizeof(uint16));
uint32 n = 0;
uint32 i = 0;
@@ -821,7 +821,7 @@
}
}
-Reader *Assembly::newReader(ArrayUInt8* array, uint32 start, uint32 end) {
+Reader *Assembly::newReader(ByteCode* array, uint32 start, uint32 end) {
return new(allocator, "Reader") Reader(array, start, end);
}
@@ -898,7 +898,7 @@
sprintf(buf, "%s%s", cur, asciiz);
}
- bytes = Reader::openFile(buf);
+ bytes = Reader::openFile(allocator, buf);
++idx;
}
lockVar->unlock();
Modified: vmkit/trunk/lib/N3/VMCore/Assembly.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Assembly.h?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Assembly.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Assembly.h Sat Oct 10 14:43:39 2009
@@ -22,6 +22,8 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Type.h"
+#include "VMArray.h"
+
namespace llvm {
class GenericValue;
}
@@ -58,6 +60,7 @@
class VMObject;
class VMGenericClass;
class VMGenericMethod;
+class ByteCode;
class Section : public mvm::PermanentObject {
public:
@@ -99,8 +102,8 @@
uint32 count;
uint32 sizeMask;
- void readRow(uint32* result, uint32 row, ArrayUInt8* array);
- uint32 readIndexInRow(uint32 row, uint32 index, ArrayUInt8* array);
+ void readRow(uint32* result, uint32 row, ByteCode* array);
+ uint32 readIndexInRow(uint32 row, uint32 index, ByteCode* array);
};
@@ -136,17 +139,6 @@
typedef VMCommonClass* (*signatureVector_t)(uint32 op, Assembly* ass,
uint32& offset, VMGenericClass* genClass, VMGenericMethod* genMethod);
-// class ByteCode : mvm::PermanentObject {
-// public:
-// ByteCode(mvm::BumpPtrAllocator &allocator, int size) {
-// this->size = size;
-// this->elements = mvm::BumpPtrAllocator::operator new(0, "ByteCode", size * sizeof(uint8));
-// }
-
-// uint32 size;
-// uint8 *elements;
-// };
-
class Assembly : public mvm::PermanentObject {
public:
virtual void print(mvm::PrintBuffer* buf) const;
@@ -182,7 +174,7 @@
mvm::Lock* lockVar;
mvm::Cond* condVar;
const UTF8* name;
- ArrayUInt8* bytes;
+ ByteCode* bytes;
Section* textSection;
Section* rsrcSection;
Section* relocSection;
@@ -210,11 +202,9 @@
int resolve(int doResolve, const char *ext);
static const UTF8* readUTF8(N3* vm, uint32 len, Reader* reader);
- static const UTF8* readUTF8(N3* vm, uint32 len, ArrayUInt8* bytes,
- uint32& offset);
+ static const UTF8* readUTF8(N3* vm, uint32 len, ByteCode* bytes, uint32& offset);
static const ArrayUInt16* readUTF16(N3* vm, uint32 len, Reader* reader);
- static const ArrayUInt16* readUTF16(N3* vm, uint32 len,
- ArrayUInt8* bytes, uint32& offset);
+ static const ArrayUInt16* readUTF16(N3* vm, uint32 len, ByteCode* bytes, uint32& offset);
const UTF8* readString(N3* vm, uint32 offset);
void readTables(Reader* reader);
@@ -224,7 +214,7 @@
static const char* signatureNames[0x46];
- Reader *newReader(ArrayUInt8* array, uint32 start = 0, uint32 end = 0);
+ Reader *newReader(ByteCode* array, uint32 start = 0, uint32 end = 0);
uint32 uncompressSignature(uint32& offset);
uint32 getTypeDefTokenFromMethod(uint32 token);
Modified: vmkit/trunk/lib/N3/VMCore/CLIJit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/CLIJit.cpp?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/CLIJit.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/CLIJit.cpp Sat Oct 10 14:43:39 2009
@@ -968,7 +968,7 @@
uint32 CLIJit::readExceptionTable(uint32 offset, bool fat, VMGenericClass* genClass, VMGenericMethod* genMethod) {
Assembly* ass = compilingClass->assembly;
- ArrayUInt8* bytes = ass->bytes;
+ ByteCode* bytes = ass->bytes;
uint32 nbe = 0;
if (fat) {
nbe = (READ_U3(bytes, offset) - 4) / 24;
@@ -1151,7 +1151,7 @@
PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "tiny or fat compile %s\n",
mvm::PrintBuffer(compilingMethod).cString());
uint32 offset = compilingMethod->offset;
- ArrayUInt8* bytes = compilingClass->assembly->bytes;
+ ByteCode* bytes = compilingClass->assembly->bytes;
uint8 header = READ_U1(bytes, offset);
bool tiny = false;
uint32 localVarSig = 0;
@@ -1329,7 +1329,7 @@
PRINT_DEBUG(N3_COMPILE, 1, COLOR_NORMAL, "tiny or fat inline compile %s\n",
mvm::PrintBuffer(compilingMethod).cString());
uint32 offset = compilingMethod->offset;
- ArrayUInt8* bytes = compilingClass->assembly->bytes;
+ ByteCode* bytes = compilingClass->assembly->bytes;
uint8 header = READ_U1(bytes, offset);
bool tiny = false;
uint32 localVarSig = 0;
Modified: vmkit/trunk/lib/N3/VMCore/MSCorlib.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/MSCorlib.inc?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/MSCorlib.inc (original)
+++ vmkit/trunk/lib/N3/VMCore/MSCorlib.inc Sat Oct 10 14:43:39 2009
@@ -49,7 +49,7 @@
uint32 size = array->size;
uint32 offset = inSection->rawAddress + (rva - inSection->virtualAddress);
- ArrayUInt8* bytes = ass->bytes;
+ ByteCode* bytes = ass->bytes;
if (bs == MSCorlib::pChar) {
for (uint32 i = 0; i < size; ++i) {
Modified: vmkit/trunk/lib/N3/VMCore/Reader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Reader.cpp?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Reader.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/Reader.cpp Sat Oct 10 14:43:39 2009
@@ -53,16 +53,19 @@
const int Reader::SeekCur = SEEK_CUR;
const int Reader::SeekEnd = SEEK_END;
-ArrayUInt8* Reader::openFile(char* path) {
+ByteCode::ByteCode(mvm::BumpPtrAllocator &allocator, int size) {
+ this->size = size;
+ this->elements = (uint8*)allocator.Allocate(size * sizeof(uint8), "uint8[]");
+}
+
+ByteCode* Reader::openFile(mvm::BumpPtrAllocator &allocator, char* path) {
FILE* fp = fopen(path, "r");
- ArrayUInt8* res = 0;
+ ByteCode* res = 0;
if (fp != 0) {
fseek(fp, 0, SeekEnd);
long nbb = ftell(fp);
fseek(fp, 0, SeekSet);
- // printf("---> %p\n", MSCorlib::arrayByte);
- // MSCorlib::arrayByte->doNew(nbb);
- res = ArrayUInt8::acons(nbb, MSCorlib::arrayByte);
+ res = new(allocator, "ByteCode") ByteCode(allocator, nbb);
fread(res->elements, nbb, 1, fp);
fclose(fp);
}
@@ -70,7 +73,9 @@
}
uint8 Reader::readU1() {
- return bytes->at(cursor++);
+ if(cursor >= (uint32)bytes->size)
+ VMThread::get()->vm->error("readU1 outside the buffer");
+ return bytes->elements[cursor++];
}
sint8 Reader::readS1() {
@@ -107,7 +112,7 @@
return tmp | (((sint64)(readS8())) << 32);
}
-Reader::Reader(ArrayUInt8* array, uint32 start, uint32 end) {
+Reader::Reader(ByteCode* array, uint32 start, uint32 end) {
if (!end)
end = array->size;
Modified: vmkit/trunk/lib/N3/VMCore/Reader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/Reader.h?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/Reader.h (original)
+++ vmkit/trunk/lib/N3/VMCore/Reader.h Sat Oct 10 14:43:39 2009
@@ -14,19 +14,24 @@
#include "types.h"
-#include "VMArray.h"
-
namespace n3 {
+class ByteCode : public mvm::PermanentObject {
+public:
+ sint32 size;
+ uint8 *elements;
+
+ ByteCode(mvm::BumpPtrAllocator &allocator, int nbb);
+};
class Reader : public mvm::PermanentObject {
public:
- ArrayUInt8* bytes;
+ ByteCode* bytes;
uint32 min;
uint32 cursor;
uint32 max;
- Reader(ArrayUInt8* array, uint32 start = 0, uint32 end = 0);
+ Reader(ByteCode* array, uint32 start = 0, uint32 end = 0);
static double readDouble(int first, int second);
static sint64 readLong(int first, int second);
@@ -35,7 +40,7 @@
static const int SeekCur;
static const int SeekEnd;
- static ArrayUInt8* openFile(char* path);
+ static ByteCode* openFile(mvm::BumpPtrAllocator &allocator, char* path);
uint8 readU1();
sint8 readS1();
uint16 readU2();
@@ -49,43 +54,41 @@
void seek(uint32 pos, int from);
virtual void print(mvm::PrintBuffer* buf) const;
- virtual void TRACER;
};
-static sint8 inline READ_S1(ArrayUInt8* bytes, uint32& offset) {
+static sint8 inline READ_S1(ByteCode* bytes, uint32& offset) {
return (sint8)(bytes->elements[offset++]);
}
-static uint8 inline READ_U1(ArrayUInt8* bytes, uint32& offset) {
+static uint8 inline READ_U1(ByteCode* bytes, uint32& offset) {
return(uint8)(bytes->elements[offset++]);
}
-static sint16 inline READ_S2(ArrayUInt8* bytes, uint32& offset) {
+static sint16 inline READ_S2(ByteCode* bytes, uint32& offset) {
sint16 val = READ_S1(bytes, offset);
return val | (READ_U1(bytes, offset) << 8);
}
-static uint16 inline READ_U2(ArrayUInt8* bytes, uint32& offset) {
+static uint16 inline READ_U2(ByteCode* bytes, uint32& offset) {
uint16 val = READ_U1(bytes, offset);
return val | (READ_U1(bytes, offset) << 8);
}
-static sint32 inline READ_S4(ArrayUInt8* bytes, uint32& offset) {
+static sint32 inline READ_S4(ByteCode* bytes, uint32& offset) {
sint32 val = READ_U2(bytes, offset);
return val | (READ_U2(bytes, offset) << 16);
}
-static uint32 inline READ_U3(ArrayUInt8* bytes, uint32& offset) {
+static uint32 inline READ_U3(ByteCode* bytes, uint32& offset) {
uint32 val = READ_U2(bytes, offset);
return val | (READ_U1(bytes, offset) << 16);
}
-
-static uint32 inline READ_U4(ArrayUInt8* bytes, uint32& offset) {
+static uint32 inline READ_U4(ByteCode* bytes, uint32& offset) {
return READ_S4(bytes, offset);
}
-static uint32 inline READ_U8(ArrayUInt8* bytes, uint32& offset) {
+static uint32 inline READ_U8(ByteCode* bytes, uint32& offset) {
uint64 val1 = READ_U4(bytes, offset);
uint64 val2 = READ_U4(bytes, offset);
return (val2 << 32) + val1;
Modified: vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp?rev=83723&r1=83722&r2=83723&view=diff
==============================================================================
--- vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/N3/VMCore/VirtualTables.cpp Sat Oct 10 14:43:39 2009
@@ -56,12 +56,6 @@
}
void ThreadSystem::TRACER {
- //nonDaemonLock->MARK_AND_TRACE;
- //nonDaemonVar->MARK_AND_TRACE;
-}
-
-void Reader::TRACER {
- bytes->MARK_AND_TRACE;
}
void CacheNode::TRACER {
@@ -221,7 +215,6 @@
loadedTokenFields->CALL_TRACER;
//lockVar->MARK_AND_TRACE;
//condVar->MARK_AND_TRACE;
- bytes->MARK_AND_TRACE;
textSection->CALL_TRACER;
rsrcSection->CALL_TRACER;
relocSection->CALL_TRACER;
More information about the vmkit-commits
mailing list