You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/10/03 04:26:49 UTC
svn commit: r452293 [2/2] - in /incubator/harmony/enhanced/drlvm/trunk/vm:
gc/src/ vmcore/include/
Added: incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.cpp
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.cpp?view=auto&rev=452293
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.cpp (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.cpp Mon Oct 2 19:26:48 2006
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+/**
+ * @author Ivan Volosyuk
+ */
+
+#include "gc_types.h"
+#include "collect.h"
+
+#ifdef POINTER64
+
+#define ROOTS_CAPACITY 64
+
+Partial_Reveal_Object *heap_null;
+
+struct RootArray {
+ Reference *heap_chunk;
+ int pos;
+
+ RootArray() : pos(0), heap_chunk(0) {}
+
+ void allocate() {
+ pos = 0;
+ heap_chunk = (Reference*) heap.roots_pos;
+ heap.roots_pos += ROOTS_CAPACITY * sizeof(Reference);
+ if (heap.roots_pos > heap.roots_end) {
+ DIE2("gc", "not enough reserved space for roots");
+ }
+ }
+
+ Slot make_slot(Partial_Reveal_Object *obj) {
+ Slot slot(heap_chunk + pos);
+ slot.write(obj);
+ pos++;
+ return slot;
+ }
+
+};
+
+template <typename RefType>
+struct Roots : private RootArray {
+ Roots<RefType> *next;
+ RefType roots[ROOTS_CAPACITY];
+ static Roots<RefType> *base;
+ static Roots<RefType> *active;
+
+ Roots() : next(0) {}
+
+ void update_one() {
+ for(int i = 0; i < pos; i++) {
+ Slot slot(heap_chunk + i);
+ Partial_Reveal_Object *obj = slot.read();
+ assert((Ptr)obj >= heap.base && (Ptr)obj < heap.ceiling);
+ assert(((size_t)obj & (GC_OBJECT_ALIGNMENT - 1)) == 0);
+ assert(obj == heap_null || obj->vtable());
+ store(roots[i], obj);
+ }
+ }
+
+ Partial_Reveal_Object *fetch(RefType r);
+ void store(RefType r, Partial_Reveal_Object *obj);
+
+ public:
+
+ Slot add_root(RefType ref) {
+ roots[pos] = ref;
+ Partial_Reveal_Object *obj = fetch(ref);
+ assert((Ptr)obj >= heap.base && (Ptr)obj < heap.ceiling);
+ assert(((size_t)obj & (GC_OBJECT_ALIGNMENT - 1)) == 0);
+ assert(obj == heap_null || obj->vt());
+ Slot slot = make_slot(obj);
+
+ if (pos >= ROOTS_CAPACITY) {
+ if (next == 0) next = new Roots<RefType>();
+ next->allocate();
+ active = next;
+ }
+ return slot;
+ }
+
+ static void update() {
+ for(Roots<RefType> *r = base; true; r = r->next) {
+ r->update_one();
+ if (r->pos != ROOTS_CAPACITY) return;
+ }
+ }
+
+ static void clear() {
+ if (base == 0) base = new Roots<RefType>();
+ base->allocate();
+ active = base;
+ }
+
+ static int count() {
+ int res = 0;
+ for(Roots<RefType> *r = base; true; r = r->next) {
+ res += r->pos;
+ if (r->pos != ROOTS_CAPACITY) return res;
+ }
+ }
+};
+
+struct InteriorPointer {
+ void **slot;
+ int offset;
+};
+
+typedef Roots<Partial_Reveal_Object**> DirectRoots;
+typedef Roots<InteriorPointer> InteriorRoots;
+typedef Roots<uint32*> CompressedRoots;
+
+template<> DirectRoots *DirectRoots::active = 0;
+template<> DirectRoots *DirectRoots::base = 0;
+template<> CompressedRoots *CompressedRoots::active = 0;
+template<> CompressedRoots *CompressedRoots::base = 0;
+template<> InteriorRoots *InteriorRoots::active = 0;
+template<> InteriorRoots *InteriorRoots::base = 0;
+
+Partial_Reveal_Object* DirectRoots::fetch(Partial_Reveal_Object **r) {
+ assert(*r != 0);
+ return *r;
+}
+void DirectRoots::store(Partial_Reveal_Object **r, Partial_Reveal_Object *o) {
+ assert(o != 0);
+ assert(*r == o || o != heap_null);
+ *r = o;
+}
+
+Partial_Reveal_Object* InteriorRoots::fetch(InteriorPointer p) {
+ Partial_Reveal_Object *res = (Partial_Reveal_Object*) (*(Ptr*)p.slot - p.offset);
+ assert(res != heap_null);
+ if (res == 0) return heap_null;
+ return res;
+}
+void InteriorRoots::store(InteriorPointer p, Partial_Reveal_Object *o) {
+ assert(o != 0);
+ if (o == heap_null) o = 0;
+ *(Ptr*)p.slot = (Ptr)o + p.offset;
+}
+
+Partial_Reveal_Object* CompressedRoots::fetch(uint32 *cr) {
+ return (Partial_Reveal_Object*) (heap.base + *cr);
+}
+void CompressedRoots::store(uint32 *cr, Partial_Reveal_Object *o) {
+ assert(o != 0);
+ *cr = (uint32)((Ptr)o - heap.base);
+}
+
+Slot make_direct_root(Partial_Reveal_Object **root) {
+ return DirectRoots::active->add_root(root);
+}
+
+static inline Slot make_interior_root(void **slot, int offset) {
+ InteriorPointer p;
+ p.slot = slot;
+ p.offset = offset;
+ return InteriorRoots::active->add_root(p);
+}
+
+static inline Slot make_compressed_root(uint32 *cr) {
+ return CompressedRoots::active->add_root(cr);
+}
+
+void init_slots() {
+ heap.roots_start = heap.roots_pos = heap.roots_end - 1024 * 1024;
+ if (heap.ceiling > heap.roots_start) heap.ceiling = heap.roots_start;
+ heap_null = (Partial_Reveal_Object*) heap.base;
+}
+
+void roots_clear() {
+ heap.roots_pos = heap.roots_start;
+ DirectRoots::clear();
+ InteriorRoots::clear();
+ CompressedRoots::clear();
+}
+
+void roots_update() {
+ INFO2("gc.roots", "Roots: "
+ << DirectRoots::count() << " direct, "
+ << InteriorRoots::count() << " interior, "
+ << CompressedRoots::count() << " compressed")
+ DirectRoots::update();
+ InteriorRoots::update();
+ CompressedRoots::update();
+}
+
+void gc_add_compressed_root_set_entry(uint32 *ref, Boolean is_pinned) {
+ assert(!is_pinned);
+ Slot root = make_compressed_root(ref);
+ gc_add_root_set_entry_slot(root);
+}
+
+
+#else /* No EM64T */
+
+struct InteriorPointer {
+ Partial_Reveal_Object *obj;
+ int offset;
+ Partial_Reveal_Object **interior_ref;
+};
+
+fast_list<InteriorPointer,256> interior_pointers;
+
+inline Slot make_interior_root(void **slot, int offset) {
+ InteriorPointer ip;
+ ip.obj = (Partial_Reveal_Object*) (*(unsigned char**)slot - offset);
+ ip.interior_ref = (Partial_Reveal_Object**)slot;
+ ip.offset = offset;
+ InteriorPointer& ips = interior_pointers.push_back(ip);
+ return Slot(&ips.obj);
+}
+
+void init_slots() {
+}
+
+void roots_clear() {
+ interior_pointers.clear();
+}
+
+void roots_update() {
+ fast_list<InteriorPointer,256>::iterator begin = interior_pointers.begin();
+ fast_list<InteriorPointer,256>::iterator end = interior_pointers.end();
+
+ for(fast_list<InteriorPointer,256>::iterator i = begin; i != end; ++i) {
+ *(*i).interior_ref = (Partial_Reveal_Object*)((unsigned char*)(*i).obj + (*i).offset);
+ }
+}
+#endif /* EM64T */
+
+void gc_add_root_set_entry_slot(Slot root) {
+ switch(gc_type) {
+ case GC_COPY: gc_copy_add_root_set_entry(root); break;
+ case GC_FORCED: gc_forced_add_root_set_entry(root); break;
+ case GC_SLIDE_COMPACT: gc_slide_add_root_set_entry(root); break;
+ case GC_CACHE: gc_cache_add_root_set_entry(root); break;
+
+ case GC_FULL:
+ default: abort();
+ }
+}
+
+void gc_add_root_set_entry(Managed_Object_Handle *ref, Boolean is_pinned) {
+ assert(!is_pinned);
+ Slot root = make_direct_root((Partial_Reveal_Object**) ref);
+ gc_add_root_set_entry_slot(root);
+}
+
+void gc_add_root_set_entry_interior_pointer (void **slot, int offset, Boolean is_pinned) {
+ assert(!is_pinned);
+ // FIXME: em64t bug, no handling for null root
+ Slot root = make_interior_root(slot, offset);
+ gc_add_root_set_entry_slot(root);
+}
+
+
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.h?view=auto&rev=452293
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.h (added)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.h Mon Oct 2 19:26:48 2006
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * 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.
+ */
+/**
+ * @author Ivan Volosyuk
+ */
+
+#ifndef __SLOT_H__
+#define __SLOT_H__
+
+#include "open/types.h"
+#include "fast_list.h"
+
+struct Partial_Reveal_VTable;
+class Partial_Reveal_Object;
+typedef unsigned char *Ptr;
+extern Ptr heap_base;
+extern size_t max_heap_size;
+
+// Bits in object headers
+#define FORWARDING_BIT 1
+#define RESCAN_BIT 2
+#define GC_OBJECT_MARK_BIT_MASK 0x00000080
+#define MARK_BITS 3
+
+#define HASHCODE_IS_ALLOCATED_BIT 4
+#define HASHCODE_IS_SET_BIT 8
+#define OBJECT_IS_PINNED_BITS (7 << 4)
+#define OBJECT_IS_PINNED_INCR (1 << 4)
+
+void init_slots();
+
+typedef uint32 Reference;
+
+class Slot {
+ Reference *s;
+ public:
+
+ Slot(Reference *slot) { s = slot; }
+ void* ptr() { return (void*) s; }
+
+#ifdef POINTER64
+ void write(Partial_Reveal_Object *obj) { *s = (Ptr)obj - heap_base; }
+ Partial_Reveal_Object *read() { return (Partial_Reveal_Object*)(heap_base + *s); }
+
+ void write_raw(Reference data) { *s = data; }
+ Reference read_raw() { return *s; }
+
+ Reference addr() { return (Reference) ((Ptr)s - (Ptr)heap_base); }
+
+#else
+ Slot(Partial_Reveal_Object **root) { s = (Reference*)root; }
+ void write(Partial_Reveal_Object *obj) { *s = (Reference)obj; }
+ Partial_Reveal_Object *read() { return (Partial_Reveal_Object*)*s; }
+
+ void write_raw(Reference data) { *s = data; }
+ Reference read_raw() { return *s; }
+
+ Reference addr() { return (Reference)s; }
+#endif
+};
+
+#ifdef POINTER64
+ extern Partial_Reveal_Object *heap_null;
+ extern Ptr vtable_base;
+ inline Partial_Reveal_VTable *ah_to_vtable(Allocation_Handle ah) {
+ return (Partial_Reveal_VTable*) (vtable_base + (uint32)ah);
+
+ }
+
+ inline Partial_Reveal_Object *fw_to_pointer(Allocation_Handle ah) {
+ assert(ah > 0 && ah < max_heap_size);
+ return (Partial_Reveal_Object*) (heap_base + (uint32)ah);
+ }
+
+ inline Reference pointer_to_fw(Partial_Reveal_Object *obj) {
+ return (Ptr)obj - (Ptr) heap_base + FORWARDING_BIT;
+ }
+
+ extern Slot make_direct_root(Partial_Reveal_Object **root);
+#else
+#define heap_null ((Partial_Reveal_Object*)0)
+ inline Partial_Reveal_VTable *ah_to_vtable(Allocation_Handle ah) {
+ return (Partial_Reveal_VTable*) ah;
+ }
+
+ inline Partial_Reveal_Object *fw_to_pointer(Allocation_Handle ah) {
+ return (Partial_Reveal_Object*) ah;
+ }
+
+ inline Reference pointer_to_fw(Partial_Reveal_Object *obj) {
+ return (Reference) obj | FORWARDING_BIT;
+ }
+
+ static inline Slot make_direct_root(Partial_Reveal_Object **root) {
+ return Slot(root);
+ }
+#endif
+
+void gc_add_root_set_entry_slot(Slot root);
+
+#endif /* __SLOT_H__ */
Propchange: incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/slot.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/timer.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/timer.h?view=diff&rev=452293&r1=452292&r2=452293
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/timer.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/gc/src/timer.h Mon Oct 2 19:26:48 2006
@@ -24,26 +24,6 @@
action_name action_params; \
timer_##action_name.finish(); }
-#ifdef _WIN32
-static __declspec(naked) __int64
-ticks(void) {
- __asm {
- rdtsc
- ret
- }
-}
-#else
-static int64
-ticks(void) {
- int64 val;
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
- return val;
-}
-#endif
-
-extern int64 timer_start;
-extern int64 timer_dt;
-
class Timer {
const char *action;
const char *category;
@@ -55,39 +35,31 @@
action = str;
finished = false;
category = "gc.time";
- start = ticks();
+ start = apr_time_now();
}
Timer(const char *str, const char *_category) {
action = str;
category = _category;
finished = false;
- start = ticks();
+ start = apr_time_now();
}
void finish() {
finished = true;
- apr_time_t end = ticks();
- INFO2(category, action << " " << (end - start) / timer_dt / 1000 << " ms");
+ apr_time_t end = apr_time_now();
+ INFO2(category, action << " " << (end - start + 500) / 1000 << " ms");
}
~Timer() {
if (!finished) finish();
}
- apr_time_t dt() { return ticks() - start; }
+ apr_time_t dt() { return apr_time_now() - start; }
};
-inline void timer_init() {
- timer_start = ticks();
-}
-
-inline void timer_calibrate(apr_time_t time_from_start) {
- int64 ticks_from_start = ticks() - timer_start;
- int64 dt = ticks_from_start / time_from_start;
- timer_dt = dt;
-
-}
+inline void timer_init() {}
+inline void timer_calibrate(apr_time_t time_from_start) {}
#else
# define TIME(action_name, action_params) action_name action_params
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h?view=diff&rev=452293&r1=452292&r2=452293
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/vmcore/include/version_svn_tag.h Mon Oct 2 19:26:48 2006
@@ -18,6 +18,6 @@
#ifndef _VERSION_SVN_TAG_
#define _VERSION_SVN_TAG_
-#define VERSION_SVN_TAG "450932"
+#define VERSION_SVN_TAG "452149"
#endif // _VERSION_SVN_TAG_