Commit 0c6b51f1 authored by Marius Wachtler's avatar Marius Wachtler

bjit: fix problem with creating very large sets, tuples,..

the fixed blocksize of our region allocator was too small for very large actions
fix this by using the more powerful llvm::BumpPtrAllocator which handles allocation larger than the slab size
parent e21bb8f2
......@@ -2520,16 +2520,4 @@ PatchpointInitializationInfo initializePatchpoint3(void* slowpath_func, uint8_t*
return PatchpointInitializationInfo(slowpath_start, slowpath_rtn_addr, continue_addr, std::move(live_outs));
}
void* Rewriter::RegionAllocator::alloc(size_t bytes) {
assert(bytes <= BLOCK_SIZE);
if (cur_offset + bytes > BLOCK_SIZE) {
blocks.emplace_back();
cur_offset = 0;
}
char* rtn = blocks.back() + cur_offset;
cur_offset += bytes;
return rtn;
}
}
......@@ -330,30 +330,9 @@ enum class ActionType { NORMAL, GUARD, MUTATION };
#define LOCATION_PLACEHOLDER ((RewriterVar*)1)
class Rewriter : public ICSlotRewrite::CommitHook {
private:
class RegionAllocator {
public:
static const int BLOCK_SIZE = 1024; // reserve a bit of space for list/malloc overhead
std::list<char[BLOCK_SIZE]> blocks;
int cur_offset = BLOCK_SIZE + 1;
void* alloc(size_t bytes);
};
template <typename T> class RegionAllocatorAdaptor : public std::allocator<T> {
private:
RegionAllocator* allocator;
public:
T* allocate(size_t n) { return (T*)allocator->alloc(n); }
void deallocate(T* p, size_t n) {
// do nothing
}
};
private:
// This needs to be the first member:
RegionAllocator allocator;
llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 512> allocator;
// The rewriter has refcounting logic for handling owned RewriterVars. If we own memory inside those RewriterVars,
// we need to register that via registerOwnedAttr, which ends up here:
......@@ -361,7 +340,7 @@ private:
protected:
// Allocates `bytes` bytes of data. The allocation will get freed when the rewriter gets freed.
void* regionAlloc(size_t bytes) { return allocator.alloc(bytes); }
void* regionAlloc(size_t bytes) { return allocator.Allocate(bytes, 16 /* alignment */); }
// Helps generating the best code for loading a const integer value.
// By keeping track of the last known value of every register and reusing it.
......@@ -425,7 +404,7 @@ protected:
Rewriter(std::unique_ptr<ICSlotRewrite> rewrite, int num_args, const LiveOutSet& live_outs,
bool needs_invalidation_support = true);
std::deque<RewriterAction, RegionAllocatorAdaptor<RewriterAction>> actions;
std::deque<RewriterAction> actions;
template <typename F> RewriterAction* addAction(F&& action, llvm::ArrayRef<RewriterVar*> vars, ActionType type) {
assertPhaseCollecting();
for (RewriterVar* var : vars) {
......
# this used to crash the bjit
for i in range(1000):
s = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment