From: <dgr...@us...> - 2010-01-08 22:39:57
|
Revision: 12472 http://x10.svn.sourceforge.net/x10/?rev=12472&view=rev Author: dgrove-oss Date: 2010-01-08 22:39:45 +0000 (Fri, 08 Jan 2010) Log Message: ----------- WIP in cleaning up C++ object model so that Ref/Object can be merged into Object. Also fix bug in C++ codegen found by Olivier for Struct constructors where one constructor calls another constructor of the same Struct. Modified Paths: -------------- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime/src-cpp/x10/lang/Deque.cc trunk/x10.runtime/src-cpp/x10/lang/Deque.h trunk/x10.runtime/src-cpp/x10/lang/Object.cc trunk/x10.runtime/src-cpp/x10/lang/Object.h trunk/x10.runtime/src-cpp/x10/lang/Rail.cc trunk/x10.runtime/src-cpp/x10/lang/Rail.h trunk/x10.runtime/src-cpp/x10/lang/Ref.cc trunk/x10.runtime/src-cpp/x10/lang/Ref.h trunk/x10.runtime/src-cpp/x10/lang/String.cc trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicReference.h trunk/x10.runtime/src-cpp/x10aux/basic_functions.cc trunk/x10.runtime/src-cpp/x10aux/network.cc Modified: trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-01-08 22:39:45 UTC (rev 12472) @@ -1827,7 +1827,8 @@ } } else if (call.kind() == ConstructorCall.THIS) { if (container.isX10Struct()) { - sw.write(CONSTRUCTOR+"("); + sw.write(CONSTRUCTOR+"(this_"); + if (call.arguments().size() > 0) sw.write(", "); } else { sw.write("this->"+CONSTRUCTOR+"("); } @@ -3629,11 +3630,11 @@ boolean needsPlaceCheck = !xf.isGlobal() && needsPlaceCheck(domain, context); boolean needsNullCheck = needsNullCheck(domain); if (mi.container().toClass().flags().isInterface()) { - sw.write(make_ref("x10::lang::Object") + " " + name + " = "+iteratorTypeRef+"("); - invokeInterface(n, domain, Collections.EMPTY_LIST, make_ref("x10::lang::Object"), xts.Iterable(form.type().type()), mi, needsPlaceCheck, needsNullCheck); + sw.write(make_ref("x10::lang::Reference") + " " + name + " = "+iteratorTypeRef+"("); + invokeInterface(n, domain, Collections.EMPTY_LIST, make_ref("x10::lang::Reference"), xts.Iterable(form.type().type()), mi, needsPlaceCheck, needsNullCheck); sw.write(");"); sw.newline(); } else { - sw.write(make_ref("x10::lang::Object") + " " + name + " = ("); + sw.write(make_ref("x10::lang::Reference") + " " + name + " = ("); if (needsPlaceCheck) sw.write("x10aux::placeCheck("); if (needsNullCheck) sw.write("x10aux::nullCheck("); n.print(domain, sw, tr); @@ -3647,7 +3648,7 @@ sw.begin(0); sw.write(";"); sw.allowBreak(2, " "); - sw.write("(((x10::lang::Object*)("+name+".operator->()))->*("+itableName+"->hasNext))();"); + sw.write("(((x10::lang::Reference*)("+name+".operator->()))->*("+itableName+"->hasNext))();"); sw.allowBreak(2, " "); sw.end(); @@ -3658,7 +3659,7 @@ sw.write(";"); sw.newline(); sw.write(mangled_non_method_name(form.name().id().toString())); - sw.write(" = (((x10::lang::Object*)("+name+".operator->()))->*("+itableName+"->next))();"); + sw.write(" = (((x10::lang::Reference*)("+name+".operator->()))->*("+itableName+"->next))();"); sw.newline(); for (Iterator li = n.locals().iterator(); li.hasNext(); ) { Stmt l = (Stmt) li.next(); Modified: trunk/x10.runtime/src-cpp/x10/lang/Deque.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Deque.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Deque.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -57,7 +57,7 @@ int newMask = newSize - 1; do { int oldIndex = b & oldMask; - Object *t = (Object*)(oldQ->data[oldIndex]); + Reference *t = (Reference*)(oldQ->data[oldIndex]); if (t != NULL && !casSlotNull(oldQ, oldIndex, t)) { t = NULL; } @@ -65,7 +65,7 @@ } while (++b != bf); } -void Deque::push(x10aux::ref<x10::lang::Object> t) { +void Deque::push(x10aux::ref<x10::lang::Reference> t) { Slots *q = queue; int mask = q->capacity - 1; int s = sp; @@ -78,14 +78,14 @@ } } -ref<Object> Deque::steal() { - Object *t; +ref<Reference> Deque::steal() { + Reference *t; Slots *q; int i; int b; if (sp != (b = base) && (q = queue) != NULL && // must read q after b - (t = ((Object*)q->data[i = (q->capacity - 1) & b])) != NULL && + (t = ((Reference*)q->data[i = (q->capacity - 1) & b])) != NULL && casSlotNull(q, i, t)) { base = b + 1; return t; @@ -93,13 +93,13 @@ return null; } -ref<Object> Deque::poll() { +ref<Reference> Deque::poll() { int s = sp; while (s != base) { Slots *q = queue; int mask = q->capacity - 1; int i = (s - 1) & mask; - Object *t = (Object*)(q->data[i]); + Reference *t = (Reference*)(q->data[i]); if (t == NULL || !casSlotNull(q, i, t)) break; storeSp(s - 1); Modified: trunk/x10.runtime/src-cpp/x10/lang/Deque.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Deque.h 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Deque.h 2010-01-08 22:39:45 UTC (rev 12472) @@ -53,7 +53,7 @@ * Add in store-order the given task at given slot of q. * Caller must ensure q is nonnull and index is in range. */ - inline void setSlot(Slots *q, int i, x10::lang::Object *t) { + inline void setSlot(Slots *q, int i, x10::lang::Reference *t) { q->data[i] = t; x10aux::atomic_ops::store_store_barrier(); } @@ -63,7 +63,7 @@ * CAS given slot of q to null. Caller must ensure q is nonnull * and index is in range. */ - inline bool casSlotNull(Slots *q, int i, x10::lang::Object* t) { + inline bool casSlotNull(Slots *q, int i, x10::lang::Reference* t) { return x10aux::atomic_ops::compareAndSet_ptr(&(q->data[i]), t, NULL) == t; } @@ -87,27 +87,27 @@ * Pushes a task. Called only by current thread. * @param t the task. Caller must ensure nonnull */ - void push(x10aux::ref<x10::lang::Object> t); + void push(x10aux::ref<x10::lang::Reference> t); /** * Tries to take a task from the base of the queue, failing if * either empty or contended. * @return a task, or null if none or contended. */ - x10aux::ref<x10::lang::Object> steal(); + x10aux::ref<x10::lang::Reference> steal(); /** * Returns a popped task, or null if empty. Ensures active status * if nonnull. Called only by current thread. */ - x10aux::ref<x10::lang::Object> poll(); + x10aux::ref<x10::lang::Reference> poll(); /** * Returns next task to pop. */ - inline x10aux::ref<x10::lang::Object> peekTask() { + inline x10aux::ref<x10::lang::Reference> peekTask() { Slots *q = queue; - return q == NULL ? NULL : (x10::lang::Object*)(q->data[(sp - 1) & (q->capacity - 1)]); + return q == NULL ? NULL : (x10::lang::Reference*)(q->data[(sp - 1) & (q->capacity - 1)]); } /** Modified: trunk/x10.runtime/src-cpp/x10/lang/Object.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Object.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Object.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -7,14 +7,14 @@ using namespace x10::lang; using namespace x10aux; -x10aux::RuntimeType x10::lang::Object::rtt; +x10aux::RuntimeType x10::lang::SomeObject::rtt; -void Object::_initRTT() { +void SomeObject::_initRTT() { rtt.init(&rtt, "x10.lang.Object", 0, NULL, 0, NULL, NULL); } -itable_entry Object::_itables[1] = { itable_entry(NULL, (void*)x10aux::getRTT<Object>()) }; +itable_entry SomeObject::_itables[1] = { itable_entry(NULL, (void*)x10aux::getRTT<SomeObject>()) }; // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/lang/Object.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Object.h 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Object.h 2010-01-08 22:39:45 UTC (rev 12472) @@ -11,7 +11,7 @@ class Ref; class Any; - class Object : public Reference { + class SomeObject : public Reference { private: static x10aux::itable_entry _itables[1]; @@ -20,9 +20,9 @@ virtual x10aux::itable_entry* _getITables() { return _itables; } - Object(){ } + SomeObject(){ } - virtual ~Object() { } + virtual ~SomeObject() { } virtual x10_int hashCode() = 0; Modified: trunk/x10.runtime/src-cpp/x10/lang/Rail.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Rail.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Rail.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -46,7 +46,7 @@ buf.write(fs); } -void x10::lang::Rail_serializeAndSendPut(Place dst_place_, ref<Object> df, x10_ubyte code, +void x10::lang::Rail_serializeAndSendPut(Place dst_place_, ref<Reference> df, x10_ubyte code, serialization_id_t _id, void* data, size_t size) { serialization_buffer buf; @@ -57,7 +57,7 @@ x10aux::send_put(dst_place_.FMGL(id), _id, buf, data, size); } -void x10::lang::Rail_serializeAndSendGet(Place src_place_, ref<Object> df, x10_ubyte code, +void x10::lang::Rail_serializeAndSendGet(Place src_place_, ref<Reference> df, x10_ubyte code, serialization_id_t _id, void* data, size_t size) { serialization_buffer buf; Modified: trunk/x10.runtime/src-cpp/x10/lang/Rail.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Rail.h 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Rail.h 2010-01-08 22:39:45 UTC (rev 12472) @@ -179,11 +179,11 @@ void Rail_serialize_finish_state(x10aux::place dst_place, x10aux::serialization_buffer& buf); - void Rail_serializeAndSendPut(x10::lang::Place dst_place_, x10aux::ref<x10::lang::Object> df, + void Rail_serializeAndSendPut(x10::lang::Place dst_place_, x10aux::ref<x10::lang::Reference> df, x10_ubyte code, x10aux::serialization_id_t _id, void* data, size_t size); - void Rail_serializeAndSendGet(x10::lang::Place dst_place_, x10aux::ref<x10::lang::Object> df, + void Rail_serializeAndSendGet(x10::lang::Place dst_place_, x10aux::ref<x10::lang::Reference> df, x10_ubyte code, x10aux::serialization_id_t _id, void* data, size_t size); Modified: trunk/x10.runtime/src-cpp/x10/lang/Ref.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Ref.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Ref.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -99,6 +99,6 @@ } -RTT_CC_DECLS1(Ref, "x10.lang.Ref", Object) +RTT_CC_DECLS1(Ref, "x10.lang.Ref", SomeObject) // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/lang/Ref.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Ref.h 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/Ref.h 2010-01-08 22:39:45 UTC (rev 12472) @@ -22,7 +22,7 @@ class String; - class Ref : public Object { + class Ref : public SomeObject { public: RTT_H_DECLS_CLASS; @@ -102,7 +102,7 @@ virtual x10aux::ref<x10::lang::String> typeName(); // Needed for linking - do not override - virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { + virtual x10_boolean _struct_equals(x10aux::ref<Ref> other) { if (other == x10aux::ref<Ref>(this)) return true; if (this->location == x10aux::here) return false; // already tested above if (other->location == this->location && Modified: trunk/x10.runtime/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/String.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/lang/String.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -183,7 +183,7 @@ continue; } nullCheck(parms); - const ref<Object> p = parms->operator[](i); + const ref<Reference> p = parms->operator[](i); char* buf = NULL; if (p.isNull()) { ss << (buf = x10aux::alloc_printf(fmt, "null")); // FIXME: Ignore nulls for now @@ -241,7 +241,7 @@ continue; } placeCheck(nullCheck(parms)); - const ref<Object> p = parms->operator[](i); + const ref<Reference> p = parms->operator[](i); char* buf = NULL; if (p.isNull()) { ss << (buf = x10aux::alloc_printf(fmt, "null")); // FIXME: Ignore nulls for now Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicReference.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicReference.h 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicReference.h 2010-01-08 22:39:45 UTC (rev 12472) @@ -151,7 +151,7 @@ template<class T> const x10aux::serialization_id_t AtomicReference<T>::_serialization_id = - x10aux::DeserializationDispatcher::addDeserializer(AtomicReference<T>::template _deserializer<Object>); + x10aux::DeserializationDispatcher::addDeserializer(AtomicReference<T>::template _deserializer<Reference>); template<> class AtomicReference<void> { public: Modified: trunk/x10.runtime/src-cpp/x10aux/basic_functions.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/basic_functions.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10aux/basic_functions.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -96,11 +96,7 @@ x10_boolean x10aux::general_equals_impl(x10aux::ref<x10::lang::Any> x, x10aux::ref<x10::lang::Any> y) { nullCheck(x); - // TODO: HACK: FIXME: This is not correct. - // We should be pulling the itable for Equals (once everyone implements it...) - // and using it to do the dispatch. - // This will not work for IBox<S>. - x10aux::ref<x10::lang::Object> xAsObj(x); + x10aux::ref<x10::lang::Reference> xAsObj(x); return xAsObj->equals(y); } Modified: trunk/x10.runtime/src-cpp/x10aux/network.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/network.cc 2010-01-08 20:50:25 UTC (rev 12471) +++ trunk/x10.runtime/src-cpp/x10aux/network.cc 2010-01-08 22:39:45 UTC (rev 12472) @@ -151,7 +151,7 @@ struct x10_runtime_Runtime__closure__6__hack : x10::lang::Closure { static const x10aux::serialization_id_t _serialization_id; x10aux::ref<x10::lang::VoidFun_0_0> body; - x10aux::ref<x10::lang::Object> fs; + x10aux::ref<x10::lang::Reference> fs; }; void x10aux::run_at(x10aux::place p, x10aux::ref<Reference> body) { @@ -195,13 +195,13 @@ x10aux::ref<x10::lang::Reference> real_body = body_->body; - x10aux::ref<x10::lang::Object> fs = body_->fs; + x10aux::ref<x10::lang::Reference> fs = body_->fs; serialization_id_t real_sid = real_body->_get_serialization_id(); msg_type real_id = DeserializationDispatcher::getMsgType(real_sid); _X_(ANSI_BOLD<<ANSI_X10RT<<"This is actually a kernel: "<<ANSI_RESET - <<ref<Object>(real_body)->toString()->c_str()<<" id "<<real_id + <<ref<Reference>(real_body)->toString()->c_str()<<" id "<<real_id <<" sid "<<real_sid<<" at GPU: "<<p); buf.write(fs); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |