Move ArenaBitVector into the runtime
Motivation is using arenas in the verifier.
Bug: 10921004
Change-Id: I3c7ed369194b2309a47b12a621e897e0f2f65fcf
diff --git a/runtime/Android.mk b/runtime/Android.mk
index 9236ffb..09d7311 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -25,6 +25,7 @@
barrier.cc \
base/allocator.cc \
base/arena_allocator.cc \
+ base/arena_bit_vector.cc \
base/bit_vector.cc \
base/hex_dump.cc \
base/logging.cc \
diff --git a/runtime/base/arena_bit_vector.cc b/runtime/base/arena_bit_vector.cc
new file mode 100644
index 0000000..fbbfd84
--- /dev/null
+++ b/runtime/base/arena_bit_vector.cc
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "arena_bit_vector.h"
+
+#include "base/allocator.h"
+#include "base/arena_allocator.h"
+
+namespace art {
+
+template <typename ArenaAlloc>
+class ArenaBitVectorAllocator FINAL : public Allocator,
+ public ArenaObject<kArenaAllocGrowableBitMap> {
+ public:
+ explicit ArenaBitVectorAllocator(ArenaAlloc* arena) : arena_(arena) {}
+ ~ArenaBitVectorAllocator() {}
+
+ virtual void* Alloc(size_t size) {
+ return arena_->Alloc(size, kArenaAllocGrowableBitMap);
+ }
+
+ virtual void Free(void*) {} // Nop.
+
+ private:
+ ArenaAlloc* const arena_;
+ DISALLOW_COPY_AND_ASSIGN(ArenaBitVectorAllocator);
+};
+
+ArenaBitVector::ArenaBitVector(ArenaAllocator* arena, unsigned int start_bits,
+ bool expandable, OatBitMapKind kind)
+ : BitVector(start_bits, expandable,
+ new (arena) ArenaBitVectorAllocator<ArenaAllocator>(arena)), kind_(kind) {
+ UNUSED(kind_);
+}
+
+ArenaBitVector::ArenaBitVector(ScopedArenaAllocator* arena, unsigned int start_bits,
+ bool expandable, OatBitMapKind kind)
+ : BitVector(start_bits, expandable,
+ new (arena) ArenaBitVectorAllocator<ScopedArenaAllocator>(arena)), kind_(kind) {
+ UNUSED(kind_);
+}
+
+} // namespace art
diff --git a/runtime/base/arena_bit_vector.h b/runtime/base/arena_bit_vector.h
new file mode 100644
index 0000000..d606166
--- /dev/null
+++ b/runtime/base/arena_bit_vector.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_BASE_ARENA_BIT_VECTOR_H_
+#define ART_RUNTIME_BASE_ARENA_BIT_VECTOR_H_
+
+#include "base/arena_object.h"
+#include "base/bit_vector.h"
+
+namespace art {
+
+class ArenaAllocator;
+class ScopedArenaAllocator;
+
+// Type of growable bitmap for memory tuning.
+enum OatBitMapKind {
+ kBitMapMisc = 0,
+ kBitMapUse,
+ kBitMapDef,
+ kBitMapLiveIn,
+ kBitMapBMatrix,
+ kBitMapDominators,
+ kBitMapIDominated,
+ kBitMapDomFrontier,
+ kBitMapRegisterV,
+ kBitMapTempSSARegisterV,
+ kBitMapNullCheck,
+ kBitMapClInitCheck,
+ kBitMapPredecessors,
+ kNumBitMapKinds
+};
+
+std::ostream& operator<<(std::ostream& os, const OatBitMapKind& kind);
+
+/*
+ * A BitVector implementation that uses Arena allocation.
+ */
+class ArenaBitVector : public BitVector, public ArenaObject<kArenaAllocGrowableBitMap> {
+ public:
+ ArenaBitVector(ArenaAllocator* arena, uint32_t start_bits, bool expandable,
+ OatBitMapKind kind = kBitMapMisc);
+ ArenaBitVector(ScopedArenaAllocator* arena, uint32_t start_bits, bool expandable,
+ OatBitMapKind kind = kBitMapMisc);
+ ~ArenaBitVector() {}
+
+ private:
+ const OatBitMapKind kind_; // for memory use tuning. TODO: currently unused.
+
+ DISALLOW_COPY_AND_ASSIGN(ArenaBitVector);
+};
+
+
+} // namespace art
+
+#endif // ART_RUNTIME_BASE_ARENA_BIT_VECTOR_H_