From: <ipe...@us...> - 2009-10-15 04:25:13
|
Revision: 11484 http://x10.svn.sourceforge.net/x10/?rev=11484&view=rev Author: ipeshansky Date: 2009-10-15 04:25:03 +0000 (Thu, 15 Oct 2009) Log Message: ----------- Implement X10 2.0 object serialization semantics (XTENLANG-428). - global field serialization - global method invocation - remote object allocation - every object now has a location field - we no longer tag pointers Disable serialization tracing from C++ static init code Re-enable duplicate address detection Minor formatting tweaks Modified Paths: -------------- trunk/x10.compiler/src/x10cpp/visit/Emitter.java trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.cc trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.h trunk/x10.runtime/src-cpp/x10/lang/Box.cc trunk/x10.runtime/src-cpp/x10/lang/Box.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/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/lang/String.h trunk/x10.runtime/src-cpp/x10/lang/Throwable.cc trunk/x10.runtime/src-cpp/x10/lang/Value.cc trunk/x10.runtime/src-cpp/x10/lang/Value.h trunk/x10.runtime/src-cpp/x10/runtime/Deque.cc trunk/x10.runtime/src-cpp/x10/runtime/Deque.h trunk/x10.runtime/src-cpp/x10/runtime/Thread.cc trunk/x10.runtime/src-cpp/x10/runtime/Thread.h trunk/x10.runtime/src-cpp/x10/util/GrowableRail.h trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.cc trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.h trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.cc trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.h trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.cc trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.h trunk/x10.runtime/src-cpp/x10aux/alloc.h trunk/x10.runtime/src-cpp/x10aux/basic_functions.h trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc trunk/x10.runtime/src-cpp/x10aux/ref.cc trunk/x10.runtime/src-cpp/x10aux/ref.h trunk/x10.runtime/src-cpp/x10aux/serialization.h trunk/x10.runtime/src-x10/x10/lang/Ref.x10 Modified: trunk/x10.compiler/src/x10cpp/visit/Emitter.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/Emitter.java 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.compiler/src/x10cpp/visit/Emitter.java 2009-10-15 04:25:03 UTC (rev 11484) @@ -937,7 +937,7 @@ h.write(make_ref("__T")+" "+DESERIALIZER_METHOD+"("+DESERIALIZATION_BUFFER+"& buf) {"); h.newline(4) ; h.begin(0); h.write(make_ref(klass)+" this_ = "+ - "new (x10aux::alloc<"+klass+" >()) "+klass+"();"); h.newline(); + "new (x10aux::alloc"+chevrons(klass)+"()) "+klass+"();"); h.newline(); h.write("this_->"+DESERIALIZE_BODY_METHOD+"(buf);"); h.newline(); h.write("return this_;"); h.end(); h.newline(); @@ -973,7 +973,7 @@ if (f.flags().isStatic() || query.isSyntheticField(f.name().toString())) continue; String fieldName = mangled_field_name(f.name().toString()); - w.write(fieldName+" = buf.read<"+translateType(f.type(),true)+" >();"); + w.write(fieldName+" = buf.read"+chevrons(translateType(f.type(),true))+"();"); } w.end(); w.newline(); w.write("}"); @@ -981,6 +981,145 @@ w.forceNewline(); } + void generateClassSerializationMethods(ClassType type, StreamWrapper sw) { + X10ClassType ct = (X10ClassType) type.toClass(); + X10TypeSystem ts = (X10TypeSystem) type.typeSystem(); + X10CPPContext_c context = (X10CPPContext_c) tr.context(); + ClassifiedStream w = sw.body(); + ClassifiedStream h = sw.header(); + h.forceNewline(); + + h.write("// Serialization"); h.newline(); + String klass = translateType(type); + + if (!type.flags().isAbstract()) { + // _serialization_id + h.write("public: static const x10aux::serialization_id_t "+SERIALIZATION_ID_FIELD+";"); h.newline(); + h.forceNewline(); + printTemplateSignature(ct.typeArguments(), w); + w.write("const x10aux::serialization_id_t "+klass+"::"+SERIALIZATION_ID_FIELD+" = "); + w.newline(4); + w.write("x10aux::DeserializationDispatcher::addDeserializer("); + String template = context.inTemplate() ? "template " : ""; + w.write(klass+"::"+template+DESERIALIZER_METHOD+chevrons(translateType(ts.Object()))+");"); + w.newline(); w.forceNewline(); + } + + // _serialize() + if (!type.flags().isAbstract()) { + if (type.flags().isFinal()) { + h.write("public: "); + h.write("static void "+SERIALIZE_METHOD+"("); h.begin(0); + h.write(make_ref(klass)+" this_,"); h.newline(); + h.write(SERIALIZATION_BUFFER+"& buf,"); h.newline(); + h.write("x10aux::addr_map& m) {"); h.end(); h.newline(4); h.begin(0); + h.write( "if (this_ == x10aux::null) {"); h.newline(4); h.begin(0); + h.write( klass+" v;"); h.newline(); // needed when we serialise uninitialised values + h.write( "v._serialize_body(buf, m);"); h.end(); h.newline(); + h.write( "} else {"); h.newline(4); h.begin(0); + h.write( "this_->_serialize_body(buf, m);"); h.end(); h.newline(); + h.write( "}"); h.end(); h.newline(); + h.write("}"); h.newline(); + h.forceNewline(); + } + } + + // _serialize_id() + if (!type.flags().isAbstract()) { + h.write("public: "); + if (!type.flags().isFinal()) + h.write("virtual "); + h.write("x10aux::serialization_id_t "+SERIALIZE_ID_METHOD+"() {"); + h.newline(4); h.begin(0); + h.write(" return "+SERIALIZATION_ID_FIELD+";"); h.end(); h.newline(); + h.write("}"); h.newline(); + h.forceNewline(); + } + + + // _serialize_body() + h.write("public: "); + if (!type.flags().isFinal()) + h.write("virtual "); + h.write("void "+SERIALIZE_BODY_METHOD+"("+SERIALIZATION_BUFFER+"& buf, x10aux::addr_map& m);"); + h.newline(0); h.forceNewline(); + + printTemplateSignature(ct.typeArguments(), w); + w.write("void "+klass+"::"+SERIALIZE_BODY_METHOD+ + "("+SERIALIZATION_BUFFER+"& buf, x10aux::addr_map& m) {"); + w.newline(4); w.begin(0); + Type parent = type.superClass(); + if (parent != null && parent.isClass()) { + w.write(translateType(parent)+"::"+SERIALIZE_BODY_METHOD+"(buf, m);"); + w.newline(); + } + for (int i = 0; i < type.fields().size(); i++) { + if (i != 0) + w.newline(); + FieldInstance f = (FieldInstance) type.fields().get(i); + if (f.flags().isStatic() || query.isSyntheticField(f.name().toString())) + continue; + if (!X10Flags.toX10Flags(f.flags()).isGlobal()) // only serialize global fields of classes + continue; + String fieldName = mangled_field_name(f.name().toString()); + w.write("buf.write(this->"+fieldName+",m);"); w.newline(); + } + w.end(); w.newline(); + w.write("}"); + w.newline(); w.forceNewline(); + + if (!type.flags().isAbstract()) { + // _deserialize() + h.write("public: template<class __T> static "); + h.write(make_ref("__T")+" "+DESERIALIZER_METHOD+"("+DESERIALIZATION_BUFFER+"& buf) {"); + h.newline(4) ; h.begin(0); + h.write(make_ref(klass)+" this_ = "+ + "new (x10aux::remote_alloc"+chevrons(klass)+"()) "+klass+"();"); h.newline(); + h.write("this_->"+DESERIALIZE_BODY_METHOD+"(buf);"); h.newline(); + h.write("return this_;"); + h.end(); h.newline(); + h.write("}"); h.newline(); h.forceNewline(); + } + + if (!type.flags().isAbstract()) { + if (type.flags().isFinal()) { + // _deserialize() + h.write("public: template<class __T> static "); + h.write(make_ref("__T")+" "+DESERIALIZE_METHOD+"("+DESERIALIZATION_BUFFER+"& buf) {"); + h.newline(4) ; h.begin(0); + h.write("return "+DESERIALIZER_METHOD+"<__T>(buf);"); + h.end(); h.newline(); + h.write("}"); h.newline(); h.forceNewline(); + } + } + + // _deserialize_body() + h.write("public: "); + h.write("void "+DESERIALIZE_BODY_METHOD+"("+DESERIALIZATION_BUFFER+"& buf);"); h.newline(0); + printTemplateSignature(ct.typeArguments(), w); + w.write("void "+klass+"::"+DESERIALIZE_BODY_METHOD+"("+DESERIALIZATION_BUFFER+"& buf) {"); + w.newline(4); w.begin(0); + if (parent != null && parent.isClass()) { + w.write(translateType(parent)+"::"+DESERIALIZE_BODY_METHOD+"(buf);"); + w.newline(); + } + for (int i = 0; i < type.fields().size(); i++) { + if (i != 0) + w.newline(); + FieldInstance f = (FieldInstance) type.fields().get(i); + if (f.flags().isStatic() || query.isSyntheticField(f.name().toString())) + continue; + if (!X10Flags.toX10Flags(f.flags()).isGlobal()) // only serialize global fields of classes + continue; + String fieldName = mangled_field_name(f.name().toString()); + w.write(fieldName+" = buf.read"+chevrons(translateType(f.type(),true))+"();"); + } + w.end(); w.newline(); + w.write("}"); + w.newline(); + w.forceNewline(); + } + void generateStructSerializationMethods(ClassType type, StreamWrapper sw) { X10ClassType ct = (X10ClassType) type.toClass(); X10TypeSystem ts = (X10TypeSystem) type.typeSystem(); @@ -1041,7 +1180,7 @@ if (f.flags().isStatic() || query.isSyntheticField(f.name().toString())) continue; String fieldName = mangled_field_name(f.name().toString()); - w.write(fieldName+" = buf.read<"+translateType(f.type(),true)+" >();"); + w.write(fieldName+" = buf.read"+chevrons(translateType(f.type(),true))+"();"); } w.end(); w.newline(); w.write("}"); Modified: trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2009-10-15 04:25:03 UTC (rev 11484) @@ -1235,6 +1235,7 @@ superClass, xts, "virtual ", h, members); } + emitter.generateClassSerializationMethods(currentClass, sw); } sw.end(); Modified: trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -20,6 +20,9 @@ return (new (x10aux::alloc<File__NativeFile>()) File__NativeFile())->_constructor(s); } +const x10aux::serialization_id_t File__NativeFile::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(File__NativeFile::_deserializer<Object>); + RTT_CC_DECLS1(File__NativeFile, "x10.io.File.NativeFile", Ref) x10aux::ref<String> Modified: trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/io/File__NativeFile.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -2,6 +2,7 @@ #define X10_IO_NATIVEFILE_H #include <x10aux/config.h> +#include <x10aux/serialization.h> #include <x10/lang/Ref.h> @@ -27,10 +28,29 @@ static x10aux::ref<File__NativeFile> _make(x10aux::ref<x10::lang::String> s); x10aux::ref<File__NativeFile> _constructor(x10aux::ref<x10::lang::String> s) { + this->x10::lang::Ref::_constructor(); path = s; return this; } + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<File__NativeFile> this_ = new (x10aux::remote_alloc<File__NativeFile>()) File__NativeFile(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + virtual x10aux::ref<x10::lang::String> getPath() { return path; } virtual x10aux::ref<x10::lang::String> getAbsolutePath(); Modified: trunk/x10.runtime/src-cpp/x10/lang/Box.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Box.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Box.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -21,3 +21,4 @@ } } +// vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/lang/Box.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Box.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Box.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -5,6 +5,7 @@ #include <x10aux/config.h> #include <x10aux/RTT.h> #include <x10aux/basic_functions.h> +#include <x10aux/serialization.h> #include <x10/lang/Ref.h> @@ -14,6 +15,7 @@ namespace lang { + class Object; class String; void _initRTTHelper_Box(x10aux::RuntimeType *location, const x10aux::RuntimeType *rtt); @@ -27,10 +29,29 @@ } x10aux::ref<Box<T> > _constructor(T contents_) { + this->Ref::_constructor(); FMGL(value) = contents_; return this; } + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class U> static x10aux::ref<U> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<Box> this_ = new (x10aux::remote_alloc<Box>()) Box(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + virtual T get() { return FMGL(value); } @@ -45,6 +66,9 @@ }; + template<class T> const x10aux::serialization_id_t Box<T>::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(Box<T>::template _deserializer<Object>); + template <> class Box<void> : public Ref { }; Modified: trunk/x10.runtime/src-cpp/x10/lang/Object.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Object.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Object.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -13,14 +13,9 @@ x10aux::serialization_buffer &buf, x10aux::addr_map &m) { - if (x10aux::remote_ref::is_remote(this_.operator->()) || this_.isNull()) { - // cannot dispatch for these "addresses", handle here - buf.write(Ref::_serialization_id,m); - buf.write(x10aux::remote_ref::make(this_.operator->()),m); - return; - } - _S_("Serializing an "<<ANSI_SER<<ANSI_BOLD<<"interface id"<<ANSI_RESET<<" to buf: "<<&buf); - buf.write(this_->_get_serialization_id(),m); + x10aux::serialization_id_t id = this_->_get_serialization_id(); + _S_("Serializing an "<<ANSI_SER<<ANSI_BOLD<<"interface id "<<id<<ANSI_RESET<<" to buf: "<<&buf); + buf.write(id,m); _S_("Serializing the "<<ANSI_SER<<"interface body"<<ANSI_RESET<<" to buf: "<<&buf); this_->_serialize_body(buf, m); } Modified: trunk/x10.runtime/src-cpp/x10/lang/Object.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Object.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Object.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -18,13 +18,15 @@ class Value; class Object { - private: + private: static x10aux::itable_entry _itables[1]; - public: + public: RTT_H_DECLS_CLASS virtual x10aux::itable_entry* _getITables() { return _itables; } + + x10_int location; Object(){ } Modified: trunk/x10.runtime/src-cpp/x10/lang/Ref.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Ref.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Ref.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -30,7 +30,7 @@ } const serialization_id_t Ref::_serialization_id = - DeserializationDispatcher::addDeserializer(Ref::_deserialize<Object>); + DeserializationDispatcher::addDeserializer(Ref::_deserializer<Object>); RTT_CC_DECLS1(Ref, "x10.lang.Ref", Object) Modified: trunk/x10.runtime/src-cpp/x10/lang/Ref.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Ref.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Ref.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -20,31 +20,69 @@ static x10aux::ref<Ref> _make(); - x10aux::ref<Ref> _constructor() { return this; } + x10aux::ref<Ref> _constructor() { + location = x10aux::here; + return this; + } static const x10aux::serialization_id_t _serialization_id; + // FIXME: optimize refs coming home static void _serialize(x10aux::ref<Ref> this_, x10aux::serialization_buffer &buf, x10aux::addr_map &m) { - // don't send an id, just serialise the ref (null/local/remote -- we don't care) - x10aux::remote_ref tmp = x10aux::remote_ref::make(this_.operator->()); - buf.write(tmp,m); + x10aux::serialization_id_t id = this_->_get_serialization_id(); + _S_("Serializing a "<<ANSI_SER<<ANSI_BOLD<<"class id "<<id<<ANSI_RESET<<" to buf: "<<&buf); + buf.write(id, m); + _S_("Serializing the "<<ANSI_SER<<"class body"<<ANSI_RESET<<" to buf: "<<&buf); + this_->_serialize_body(buf, m); } virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + // WARNING: this code interacts with the code in _deserialize virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { - _S_("Serialising a local Ref object of type "<<_type()->name()); - x10aux::remote_ref tmp = x10aux::remote_ref::make(this); - buf.write(tmp,m); + buf.write(this->location, m); + if (this->location == x10aux::here) { + _S_("Serialising a local Ref object of type "<<_type()->name()); + buf.write((x10aux::x10_addr_t)(size_t)this, m); + } else { + _S_("Serialising a remote Ref object of type "<<_type()->name()); + void* tmp = x10aux::remote_ref::get_remote_ref(this); + buf.write((x10aux::x10_addr_t)(size_t)tmp, m); + } }; - template<class T> static x10aux::ref<T> _deserialize(x10aux::deserialization_buffer &buf){ - return (T*)x10aux::remote_ref::take(buf.read<x10aux::remote_ref>()); + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &); + + // WARNING: this code interacts with the code in _serialize_body + template<class T> static x10aux::ref<T> _deserialize(x10aux::deserialization_buffer &buf) { + x10aux::serialization_id_t id = buf.read<x10aux::serialization_id_t>(); + x10_int loc = buf.peek<x10_int>(); + _S_("Attempting to deserialize a "<<ANSI_SER<<ANSI_BOLD<<"ref"<<ANSI_RESET<< + " (with id "<<id<<") at "<<loc<<" from buf: "<<&buf); + if (loc == x10aux::here) { // a remote object coming home to roost + _S_("\ta local object come home"); + x10aux::ref<T> ref = x10aux::DeserializationDispatcher::create<T>(buf, id); // consume the buffer + T* ptr = static_cast<T*>(x10aux::remote_ref::get_remote_ref(ref.operator->())); + //x10aux::dealloc(ref.operator->()); + return ptr; + } + // extract the id and execute a callback to instantiate the right concrete class + _S_("Deserializing a "<<ANSI_SER<<ANSI_BOLD<<"class"<<ANSI_RESET<< + " (with id "<<id<<") from buf: "<<&buf); + return x10aux::DeserializationDispatcher::create<T>(buf, id); } + virtual void _deserialize_body(x10aux::deserialization_buffer &buf) { + _S_("Deserialising a Ref object of type "<<_type()->name()); + this->location = buf.read<x10_int>(); + //assert (this->location != x10aux::here); // FIXME: optimize refs coming home and re-enable + void* ref = (void*)(size_t)buf.read<x10aux::x10_addr_t>(); + x10aux::remote_ref::set_remote_ref(this, ref); + }; + template<class T> friend class x10aux::ref; virtual x10_int hashCode(); @@ -54,10 +92,22 @@ // Needed for linking - do not override virtual x10_boolean _struct_equals(x10aux::ref<Object> other) { if (other == x10aux::ref<Ref>(this)) return true; + if (this->location == x10aux::here) return false; // already tested above + if (other->location == this->location && + x10aux::remote_ref::get_remote_ref(other.operator->()) == x10aux::remote_ref::get_remote_ref(this)) + { + return true; + } return false; } }; + template<class T> x10aux::ref<T> Ref::_deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<Ref> this_ = new (x10aux::remote_alloc<Ref>()) Ref(); + this_->_deserialize_body(buf); + return this_; + } + } } Modified: trunk/x10.runtime/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/String.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/String.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -289,6 +289,7 @@ void String::_serialize_body(x10aux::serialization_buffer& buf, x10aux::addr_map &m) { + this->Value::_serialize_body(buf, m); // only support strings that are shorter than 4billion chars x10_int sz = FMGL(content_length); buf.write(sz,m); Modified: trunk/x10.runtime/src-cpp/x10/lang/String.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/String.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/String.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -34,6 +34,7 @@ // names that also ought not to be freed. static x10aux::ref<String> _make(const char *content, bool steal = false); x10aux::ref<String> _constructor(const char *content, std::size_t content_length) { + this->Value::_constructor(); this->FMGL(content) = content; this->FMGL(content_length) = content_length; return this; Modified: trunk/x10.runtime/src-cpp/x10/lang/Throwable.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Throwable.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Throwable.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -37,12 +37,14 @@ void Throwable::_serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->Value::_serialize_body(buf, m); buf.write(FMGL(cause),m); buf.write(FMGL(message),m); } void Throwable::_deserialize_body(x10aux::deserialization_buffer &buf) { + this->Value::_deserialize_body(buf); FMGL(cause) = buf.read<x10aux::ref<Box<x10aux::ref<Throwable> > > >(); FMGL(message) = buf.read<x10aux::ref<String> >(); } @@ -70,6 +72,7 @@ x10aux::ref<Throwable> Throwable::_constructor(x10aux::ref<String> message, x10aux::ref<Throwable> cause) { + this->Value::_constructor(); if (message==x10aux::null) { //hack, value types aren't supposed to be null this->FMGL(message) = String::Lit(""); } else { Modified: trunk/x10.runtime/src-cpp/x10/lang/Value.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Value.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Value.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -15,9 +15,10 @@ void Value::_serialize(x10aux::ref<Value> this_, x10aux::serialization_buffer &buf, x10aux::addr_map &m) -{ - _S_("Serializing a "<<ANSI_SER<<ANSI_BOLD<<"value id"<<ANSI_RESET<<" to buf: "<<&buf); - buf.write(this_->_get_serialization_id(),m); +{ + x10aux::serialization_id_t id = this_->_get_serialization_id(); + _S_("Serializing a "<<ANSI_SER<<ANSI_BOLD<<"value id "<<id<<ANSI_RESET<<" to buf: "<<&buf); + buf.write(id,m); _S_("Serializing the "<<ANSI_SER<<"value body"<<ANSI_RESET<<" to buf: "<<&buf); this_->_serialize_body(buf, m); } Modified: trunk/x10.runtime/src-cpp/x10/lang/Value.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/Value.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/lang/Value.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -17,6 +17,10 @@ public: RTT_H_DECLS_CLASS + Value() { + location = x10aux::here; + } + static x10aux::ref<Value> _make(); x10aux::ref<Value> _constructor() { return this; } @@ -61,7 +65,7 @@ } template<class T> x10aux::ref<T> Value::_deserializer(x10aux::deserialization_buffer &) { - x10aux::ref<Value> this_ = new (x10aux::alloc<Value>())Value(); + x10aux::ref<Value> this_ = new (x10aux::alloc<Value>()) Value(); return this_; } } Modified: trunk/x10.runtime/src-cpp/x10/runtime/Deque.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/runtime/Deque.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/runtime/Deque.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -26,6 +26,7 @@ } ref<Deque> Deque::_constructor() { + this->x10::lang::Ref::_constructor(); queue = x10aux::alloc<Slots>(); queue->capacity = INITIAL_QUEUE_CAPACITY; queue->data = x10aux::alloc<volatile void*>(INITIAL_QUEUE_CAPACITY * sizeof(void*)); @@ -35,6 +36,9 @@ return this; } +const serialization_id_t Deque::_serialization_id = + DeserializationDispatcher::addDeserializer(Deque::_deserializer<Object>); + void Deque::growQueue() { Slots *oldQ = queue; int oldSize = oldQ->capacity; Modified: trunk/x10.runtime/src-cpp/x10/runtime/Deque.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/runtime/Deque.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/runtime/Deque.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -9,6 +9,7 @@ #include <x10rt17.h> #include <x10/lang/Ref.h> +#include <x10aux/serialization.h> namespace x10 { namespace runtime { @@ -29,6 +30,24 @@ x10aux::ref<Deque> _constructor(); + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<Deque> this_ = new (x10aux::remote_alloc<Deque>()) Deque(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + private: struct Slots { public: Modified: trunk/x10.runtime/src-cpp/x10/runtime/Thread.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/runtime/Thread.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/runtime/Thread.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -82,7 +82,10 @@ return (new (alloc<Thread>()) Thread())->_constructor(task,name); } +const serialization_id_t Thread::_serialization_id = + DeserializationDispatcher::addDeserializer(Thread::_deserializer<Object>); + // Helper method to initialize a Thread object. void Thread::thread_init(ref<VoidFun_0_0> task, const ref<String> name) Modified: trunk/x10.runtime/src-cpp/x10/runtime/Thread.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/runtime/Thread.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/runtime/Thread.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -13,6 +13,7 @@ #include <x10/lang/Ref.h> #include <x10/lang/String.h> #include <x10/lang/VoidFun_0_0.h> +#include <x10aux/serialization.h> #include <pthread.h> @@ -59,10 +60,29 @@ x10aux::ref<Thread> _constructor(x10aux::ref<x10::lang::VoidFun_0_0> task, x10aux::ref<x10::lang::String> name) { + this->x10::lang::Ref::_constructor(); thread_init(task, name); return this; } + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<Thread> this_ = new (x10aux::remote_alloc<Thread>()) Thread(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + // destructor ~Thread(); Modified: trunk/x10.runtime/src-cpp/x10/util/GrowableRail.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/GrowableRail.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/GrowableRail.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -6,6 +6,7 @@ #include <x10aux/RTT.h> #include <x10aux/rail_utils.h> #include <x10aux/ref.h> +#include <x10aux/serialization.h> #include <x10/lang/Ref.h> #include <x10/lang/Rail.h> @@ -35,12 +36,30 @@ return this->_constructor(1); } x10aux::ref<GrowableRail> _constructor(x10_int size) { - this->Ref::_constructor(); + this->x10::lang::Ref::_constructor(); _array = x10::lang::Rail<T>::make(size); _len = 0; return this; } + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class U> static x10aux::ref<U> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<GrowableRail> this_ = new (x10aux::remote_alloc<GrowableRail>()) GrowableRail(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + T set(T v, x10_int i) { grow(i+1); return (*_array)[i] = v; @@ -136,6 +155,9 @@ template<class T> x10aux::RuntimeType GrowableRail<T>::rtt; + template<class T> const x10aux::serialization_id_t GrowableRail<T>::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(GrowableRail<T>::template _deserializer<Object>); + template<> class GrowableRail<void> { public: static x10aux::RuntimeType rtt; Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -23,6 +23,9 @@ return this_; } +const x10aux::serialization_id_t AtomicBoolean::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(AtomicBoolean::_deserializer<Object>); + RTT_CC_DECLS1(AtomicBoolean, "x10.util.concurrent.atomic.AtomicBoolean", Ref) // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicBoolean.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -9,6 +9,7 @@ #include <x10rt17.h> #include <x10/lang/Ref.h> +#include <x10aux/serialization.h> namespace x10 { namespace util { @@ -26,8 +27,31 @@ static x10aux::ref<AtomicBoolean> _make(x10_boolean val); protected: - x10aux::ref<AtomicBoolean> _constructor(x10_boolean val) { _val = (val ? 1 :0); return this; } + x10aux::ref<AtomicBoolean> _constructor(x10_boolean val) { + this->x10::lang::Ref::_constructor(); + _val = (val ? 1 :0); + return this; + } + public: + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<AtomicBoolean> this_ = new (x10aux::remote_alloc<AtomicBoolean>()) AtomicBoolean(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + private: /* * Am x10_int that is constrained to a 0/1 and interpret as an x10_ boolean. Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -23,6 +23,9 @@ return this_; } +const x10aux::serialization_id_t AtomicInteger::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(AtomicInteger::_deserializer<Object>); + RTT_CC_DECLS1(AtomicInteger, "x10.util.concurrent.atomic.AtomicInteger", Ref) // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicInteger.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -9,6 +9,7 @@ #include <x10rt17.h> #include <x10/lang/Ref.h> +#include <x10aux/serialization.h> namespace x10 { namespace util { @@ -26,8 +27,31 @@ static x10aux::ref<AtomicInteger> _make(x10_int val); protected: - x10aux::ref<AtomicInteger> _constructor(x10_int val) { _val = val; return this; } + x10aux::ref<AtomicInteger> _constructor(x10_int val) { + this->x10::lang::Ref::_constructor(); + _val = val; + return this; + } + public: + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<AtomicInteger> this_ = new (x10aux::remote_alloc<AtomicInteger>()) AtomicInteger(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + private: volatile x10_int _val; Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -23,6 +23,9 @@ return this_; } +const x10aux::serialization_id_t AtomicLong::_serialization_id = + x10aux::DeserializationDispatcher::addDeserializer(AtomicLong::_deserializer<Object>); + RTT_CC_DECLS1(AtomicLong, "x10.util.concurrent.atomic.AtomicLong", Ref) // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10/util/concurrent/atomic/AtomicLong.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -9,6 +9,7 @@ #include <x10rt17.h> #include <x10/lang/Ref.h> +#include <x10aux/serialization.h> namespace x10 { namespace util { @@ -26,8 +27,31 @@ static x10aux::ref<AtomicLong> _make(x10_long val); protected: - x10aux::ref<AtomicLong> _constructor(x10_long val) { _val = val; return this; } + x10aux::ref<AtomicLong> _constructor(x10_long val) { + this->x10::lang::Ref::_constructor(); + _val = val; + return this; + } + public: + static const x10aux::serialization_id_t _serialization_id; + + virtual x10aux::serialization_id_t _get_serialization_id() { return _serialization_id; }; + + virtual void _serialize_body(x10aux::serialization_buffer &buf, x10aux::addr_map &m) { + this->x10::lang::Ref::_serialize_body(buf, m); + } + + template<class T> static x10aux::ref<T> _deserializer(x10aux::deserialization_buffer &buf) { + x10aux::ref<AtomicLong> this_ = new (x10aux::remote_alloc<AtomicLong>()) AtomicLong(); + this_->_deserialize_body(buf); + return this_; + } + + void _deserialize_body(x10aux::deserialization_buffer& buf) { + this->x10::lang::Ref::_deserialize_body(buf); + } + private: volatile x10_long _val; Modified: trunk/x10.runtime/src-cpp/x10aux/alloc.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/alloc.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/alloc.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -66,6 +66,13 @@ return ret; } + // Allocate an object with a void* prepended to it + template<class T> T* remote_alloc() { + _M_("Allocating a remote object of type " << TYPENAME(T)); + T* ret = alloc<T>(sizeof(T)+sizeof(void*)); + return (T*)(((char*)ret)+sizeof(void*)); + } + template<class T> T* realloc(T* src, size_t dsz) { _M_("Reallocing chunk " << (void*)src << " of type " << TYPENAME(T)); #ifdef X10_USE_BDWGC Modified: trunk/x10.runtime/src-cpp/x10aux/basic_functions.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/basic_functions.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/basic_functions.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -100,8 +100,8 @@ return y.isNull(); } else if (y.isNull()) { return false; // x != null, needed for remote refs - } else if (remote_ref::is_remote(x.operator->()) || remote_ref::is_remote(y.operator->())) { - return remote_ref::equals(x.operator->(), y.operator->()); + //} else if (remote_ref::is_remote(x.operator->()) || remote_ref::is_remote(y.operator->())) { + // return remote_ref::equals(x.operator->(), y.operator->()); } else { ref<x10::lang::Object> xAsObj = x; ref<x10::lang::Object> yAsObj = y; Modified: trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/deserialization_dispatcher.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -40,8 +40,8 @@ } deser_v[next_id] = deser; serialization_id_t r = next_id++; - _S_("DeserializationDispatcher registered the following handler for id: " - <<r<<": "<<std::hex<<(size_t)deser<<std::dec); + //_S_("DeserializationDispatcher registered the following handler for id: " + // <<r<<": "<<std::hex<<(size_t)deser<<std::dec); (void) is_async; // TODO: use two numbering schemes return r; } @@ -68,8 +68,8 @@ put_bfinder_v[next_id] = bfinder; put_notifier_v[next_id] = notifier; serialization_id_t r = next_id++; - _S_("DeserializationDispatcher registered the following put handler for id: " - <<r<<": "<<std::hex<<(size_t)bfinder<<std::dec); + //_S_("DeserializationDispatcher registered the following put handler for id: " + // <<r<<": "<<std::hex<<(size_t)bfinder<<std::dec); return r; } @@ -103,8 +103,8 @@ get_bfinder_v[next_id] = bfinder; get_notifier_v[next_id] = notifier; serialization_id_t r = next_id++; - _S_("DeserializationDispatcher registered the following get handler for id: " - <<r<<": "<<std::hex<<(size_t)bfinder<<std::dec); + //_S_("DeserializationDispatcher registered the following get handler for id: " + // <<r<<": "<<std::hex<<(size_t)bfinder<<std::dec); return r; } @@ -124,15 +124,15 @@ void DeserializationDispatcher::registerHandlers_ () { for (size_t i=0 ; i<next_id ; ++i) { if (i<deser_sz && deser_v[i]) { - _S_("(DeserializationDispatcher registered id "<<i<<" as an async)"); + //_S_("(DeserializationDispatcher registered id "<<i<<" as an async)"); x10aux::register_async_handler(i); } if (i<put_sz && put_bfinder_v[i]) { - _S_("(DeserializationDispatcher registered id "<<i<<" as a put)"); + //_S_("(DeserializationDispatcher registered id "<<i<<" as a put)"); x10aux::register_put_handler(i); } if (i<get_sz && get_bfinder_v[i]) { - _S_("(DeserializationDispatcher registered id "<<i<<" as a get)"); + //_S_("(DeserializationDispatcher registered id "<<i<<" as a get)"); x10aux::register_get_handler(i); } } Modified: trunk/x10.runtime/src-cpp/x10aux/ref.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/ref.cc 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/ref.cc 2009-10-15 04:25:03 UTC (rev 11484) @@ -17,34 +17,38 @@ void x10aux::throwBPE() { throwException<BadPlaceException>(); } -remote_ref remote_ref::make (void *ptr, bool immortalize) { - if (remote_ref::is_remote(ptr)) return *strip(ptr); - #if defined(X10_USE_BDWGC) || defined(X10_DEBUG_REFERENCE_LOGGER) - if (immortalize) { - ReferenceLogger::log(ptr); - } - #endif - remote_ref r = { x10aux::here, (size_t)ptr }; - return r; +x10_int x10aux::location(x10aux::ref<x10::lang::Object> obj) { + return obj->location; } -void *remote_ref::take (remote_ref r) { - if (r.loc==x10aux::here) return (void*)(size_t)r.addr; - if (r.addr==0) return NULL; - return mask(new remote_ref(r)); -} +//remote_ref remote_ref::make (void *ptr, bool immortalize) { +// if (remote_ref::is_remote(ptr)) return *strip(ptr); +// #if defined(X10_USE_BDWGC) || defined(X10_DEBUG_REFERENCE_LOGGER) +// if (immortalize) { +// ReferenceLogger::log(ptr); +// } +// #endif +// remote_ref r = { x10aux::here, (size_t)ptr }; +// return r; +//} -x10_int x10aux::location (void *ptr) { - if (remote_ref::is_remote(ptr)) return remote_ref::strip(ptr)->loc; - return x10aux::here; -} +//void *remote_ref::take (remote_ref r) { +// if (r.loc==x10aux::here) return (void*)(size_t)r.addr; +// if (r.addr==0) return NULL; +// return mask(new remote_ref(r)); +//} -bool remote_ref::equals (void *ptr1, void *ptr2) { - if (!remote_ref::is_remote(ptr1) || !remote_ref::is_remote(ptr2)) - return false; - remote_ref *r1 = remote_ref::strip(ptr1); - remote_ref *r2 = remote_ref::strip(ptr2); - return r1->loc==r2->loc && r1->addr==r2->addr; -} +//x10_int x10aux::location (void *ptr) { +// if (remote_ref::is_remote(ptr)) return remote_ref::strip(ptr)->loc; +// return x10aux::here; +//} +//bool remote_ref::equals (void *ptr1, void *ptr2) { +// if (!remote_ref::is_remote(ptr1) || !remote_ref::is_remote(ptr2)) +// return false; +// remote_ref *r1 = remote_ref::strip(ptr1); +// remote_ref *r2 = remote_ref::strip(ptr2); +// return r1->loc==r2->loc && r1->addr==r2->addr; +//} + // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-cpp/x10aux/ref.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/ref.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/ref.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -12,29 +12,34 @@ namespace x10aux { + typedef x10_ulong x10_addr_t; + struct remote_ref { - static bool is_remote (void *ref) { return ((size_t)ref) & 1; } - static remote_ref *strip (void *ref) { return (remote_ref*)(((size_t)ref) & ~1); } - static void *mask (remote_ref *ref) { return (void*)(((size_t)ref) | 1); } + static void* get_remote_ref (void *obj) { return *(void**)(((char*)obj)-sizeof(void*)); } + static void set_remote_ref (void *obj, void *ref) { *(void**)(((char*)obj)-sizeof(void*)) = ref; } - x10_int loc; - x10_ulong addr; + //static bool is_remote (void *ref) { return ((size_t)ref) & 1; } + //static remote_ref *strip (void *ref) { return (remote_ref*)(((size_t)ref) & ~1); } + //static void *mask (remote_ref *ref) { return (void*)(((size_t)ref) | 1); } - // take a (possibly masked) pointer and provide a remote_ref struct for serialisation - static remote_ref make (void *ptr, bool immortalize=true); + //x10_int loc; + //x10_addr_t addr; - // take a remote_ref struct (presumably from the wire) and create a local representation - static void *take (remote_ref r); + //// take a (possibly masked) pointer and provide a remote_ref struct for serialisation + //static remote_ref make (void *ptr, bool immortalize=true); - // compare two (masked) remote_ref pointers - static bool equals (void *ptr1, void *ptr2); + //// take a remote_ref struct (presumably from the wire) and create a local representation + //static void *take (remote_ref r); + + //// compare two (masked) remote_ref pointers + //static bool equals (void *ptr1, void *ptr2); }; - #ifndef NO_IOSTREAM - inline std::ostream &operator<<(std::ostream &o, const remote_ref &rr) { - return o << "rr("<<rr.addr<<"@"<<rr.loc<<")"; - } - #endif + //#ifndef NO_IOSTREAM + //inline std::ostream &operator<<(std::ostream &o, const remote_ref &rr) { + // return o << "rr("<<rr.addr<<"@"<<rr.loc<<")"; + //} + //#endif class __ref { protected: @@ -151,6 +156,8 @@ } #endif + x10_int location (ref<x10::lang::Object> obj); + void throwNPE() X10_PRAGMA_NORETURN; void throwBPE() X10_PRAGMA_NORETURN; @@ -164,7 +171,8 @@ template <class T> inline ref<T> placeCheck(ref<T> obj) { #if !defined(NO_PLACE_CHECKS) && !defined(NO_EXCEPTIONS) - if (remote_ref::is_remote(obj.operator->())) throwBPE(); + //if (remote_ref::is_remote(obj.operator->())) throwBPE(); + if (location(obj) != here) throwBPE(); #endif return obj; } @@ -201,12 +209,6 @@ template<class T> bool operator==(const ref<T>& _ref, x10_uint i) { return false; } template<class T> bool operator==(const ref<T>& _ref, x10_ulong l) { return false; } - x10_int location (void *ptr); - - template<class T> x10_int location (x10aux::ref<T> ptr) { - return location(ptr.operator->()); - } - } //namespace x10 Modified: trunk/x10.runtime/src-cpp/x10aux/serialization.h =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/serialization.h 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-cpp/x10aux/serialization.h 2009-10-15 04:25:03 UTC (rev 11484) @@ -129,9 +129,11 @@ // [DC] instead of threading this around everywhere, why don't we encapsulate it within the // serialization_buffer? That way the serialiation buffer always has it available, and noone // else has to be troubled by it. + // [IP] if we had proper cycle handling, we could. As it stands now, we have to be able to + // handle two refs to the same object being written into the same buffer. For that we need + // to reset the addr_map between them (but only up to a certain point). That code is too + // complex to implement right now. class addr_map { -#if 0 -NOT USED AT PRESENT int _size; const void** _ptrs; int _top; @@ -139,15 +141,18 @@ void _add(const void* ptr); bool _find(const void* ptr); public: - addr_map(int init_size = 4) : _size(init_size), _ptrs(new (x10aux::alloc<const -void*>((init_size)*sizeof(const void*)))const void*[init_size]), _top(0) { } + addr_map(int init_size = 4) : + _size(init_size), + _ptrs(new (x10aux::alloc<const void*>((init_size)*sizeof(const void*))) + const void*[init_size]), + _top(0) + { } template<class T> bool ensure_unique(const ref<T>& r) { return ensure_unique((void*) r.get()); } bool ensure_unique(const void* p); void reset() { _top = 0; assert (false); } ~addr_map() { x10aux::dealloc(_ptrs); } -#endif }; @@ -184,7 +189,6 @@ assert(buffer==NULL); } - void grow (void); size_t length (void) { return cursor - buffer; } @@ -192,7 +196,7 @@ char *steal() { char *buf = buffer; buffer = NULL; return buf; } - // default case for primitives and other things that never contain pointers + // Default case for primitives and other things that never contain pointers template<class T> struct Write; template<class T> struct Write<ref<T> >; template<typename T> void write(const T &val, addr_map &m); @@ -233,16 +237,17 @@ PRIMITIVE_WRITE(x10_ulong) PRIMITIVE_WRITE(x10_float) PRIMITIVE_WRITE(x10_double) - PRIMITIVE_WRITE(remote_ref) + //PRIMITIVE_WRITE(x10_addr_t) // already defined above + //PRIMITIVE_WRITE(remote_ref) - // case for references e.g. ref<Object>, + // Case for references e.g. ref<Object>, template<class T> struct serialization_buffer::Write<ref<T> > { static void _(serialization_buffer &buf, ref<T> val, addr_map &m); }; template<class T> void serialization_buffer::Write<ref<T> >::_(serialization_buffer &buf, ref<T> val, addr_map &m) { _S_("Serializing a "<<ANSI_SER<<ANSI_BOLD<<TYPENAME(T)<<ANSI_RESET<<" into buf: "<<&buf); - //depends what T is (interface/Ref/Value/FinalValue/Closure) + // Depends what T is (interface/Ref/Closure) T::_serialize(val,buf,m); } @@ -258,19 +263,22 @@ const char* cursor; public: - // we use the same buffers for serializing and deserializing so the - // const cast is necessary - // note that a serialization_buffer created this way can only be used for deserializing deserialization_buffer(const char *buffer_) : buffer(buffer_), cursor(buffer_) { } size_t consumed (void) { return cursor - buffer; } - // default case for primitives and other things that never contain pointers + // Default case for primitives and other things that never contain pointers template<class T> struct Read; template<class T> struct Read<ref<T> >; template<typename T> GPUSAFE T read(); + template<typename T> GPUSAFE T peek() { + const char* saved_cursor = cursor; + T val = read<T>(); + cursor = saved_cursor; + return val; + } }; // Case for non-refs (includes simple primitives like x10_int and all structs) @@ -280,6 +288,7 @@ // General case for structs template<class T> T deserialization_buffer::Read<T>::_(deserialization_buffer &buf) { _S_("Deserializing a "<<ANSI_SER<<ANSI_BOLD<<TYPENAME(T)<<ANSI_RESET<<" from buf: "<<&buf); + // Dispatch because we don't know what it is return T::_deserialize(buf); } @@ -307,15 +316,16 @@ PRIMITIVE_READ(x10_ulong) PRIMITIVE_READ(x10_float) PRIMITIVE_READ(x10_double) - PRIMITIVE_READ(remote_ref) + //PRIMITIVE_READ(x10_addr_t) // already defined above + //PRIMITIVE_READ(remote_ref) - // case for references e.g. ref<Object>, + // Case for references e.g. ref<Object>, template<class T> struct deserialization_buffer::Read<ref<T> > { GPUSAFE static ref<T> _(deserialization_buffer &buf); }; template<class T> ref<T> deserialization_buffer::Read<ref<T> >::_(deserialization_buffer &buf) { - //dispatch because we don't know what it is _S_("Deserializing a "<<ANSI_SER<<ANSI_BOLD<<TYPENAME(T)<<ANSI_RESET<<" from buf: "<<&buf); + // Dispatch because we don't know what it is return T::template _deserialize<T>(buf); } Modified: trunk/x10.runtime/src-x10/x10/lang/Ref.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Ref.x10 2009-10-15 03:28:05 UTC (rev 11483) +++ trunk/x10.runtime/src-x10/x10/lang/Ref.x10 2009-10-15 04:25:03 UTC (rev 11484) @@ -18,8 +18,8 @@ @NativeRep("c++", "x10aux::ref<x10::lang::Ref>", "x10::lang::Ref", null) public class Ref( @Native("java", "x10.lang.Place.place(#0.location())") - @Native("c++", "x10::lang::Place_methods::place(x10aux::location(#0))") - location: Place) + @Native("c++", "x10::lang::Place_methods::place((#0)->location)") + location: Place) /* @EQ implements Equals[Ref] */ implements Object { @@ -48,15 +48,15 @@ public native def typeName() : String; @Native("java", "#0.location()") - @Native("c++", "x10::lang::Place_methods::place(x10aux::location(#0))") + @Native("c++", "x10::lang::Place_methods::place((#0)->location)") public property def loc() = location; @Native("java", "#0.at(#1.id)") - @Native("c++", "(x10aux::location(#0) == (#1)->FMGL(id))") + @Native("c++", "((#0)->location == (#1)->FMGL(id))") public property def at(p:Place) = location==p; @Native("java", "#0.at(#1)") - @Native("c++", "(x10aux::location(#0) == x10aux::location(#1)... [truncated message content] |