Comments (10)
Pardon me but what does DCL mean?
No its not a concern.
One of the reasons it is necessary is because we want to lazy load the pojos to
support cyclic dependencies of classes. (Foo wraps Bar, Bar wraps Baz and Baz
wraps Foo).
If you are not comfortable with the one-time locking, you can always initialize
all your pojos on application startup.
Have a static initializer like this:
static
{
RuntimeSchema.getSchema(Foo.class);
RuntimeSchema.getSchema(Bar.class);
RuntimeSchema.getSchema(Baz.class);
// and so on ...
}
Original comment by [email protected]
on 27 Jan 2011 at 11:20
from protostuff-googlecode-exported.
DCL = Double-checked locking. It's an anti-pattern (ie it's plain wrong):
http://en.wikipedia.org/wiki/Double-checked_locking
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
Original comment by [email protected]
on 28 Jan 2011 at 12:52
from protostuff-googlecode-exported.
Its funny that effective java encourages that. (Search for double-check idiom)
devender.files.wordpress.com/2008/05/effectivejava.pdf
Mine's lacking the volatile keyword (w/c I'm thinking of using)
Now I'm not sure who to believe.
If it were up to you, how would you solve circular dependencies without lazy
loading?
Original comment by [email protected]
on 28 Jan 2011 at 1:16
from protostuff-googlecode-exported.
From the link you gave me:
JDK5 and later extends the semantics for volatile so that the system will not
allow a write of a volatile to be reordered with respect to any previous read
or write, and a read of a volatile cannot be reordered with respect to any
following read or write. See this entry in Jeremy Manson's blog for more
details.
With this change, the Double-Checked Locking idiom can be made to work by
declaring the helper field to be volatile. This does not work under JDK4 and
earlier.
-------- without volatile
If Helper is an immutable object, such that all of the fields of Helper are
final, then double-checked locking will work without having to use volatile
fields. The idea is that a reference to an immutable object (such as a String
or an Integer) should behave in much the same way as an int or float; reading
and writing references to immutable objects are atomic.
Conclusion:
protostuff is a jdk5 library. And both MappedSchema and RuntimeSchema are
immutable objects (all fields are final).
Would you agree that no changes are needed with the current codebase?
Original comment by [email protected]
on 28 Jan 2011 at 2:00
- Changed state: Done
from protostuff-googlecode-exported.
There's a need for volatile for the fields of RuntimeSchema.Mapped class
however.
I'll add that in.
Cheers
Original comment by [email protected]
on 28 Jan 2011 at 2:06
- Changed state: Accepted
from protostuff-googlecode-exported.
you know the code better than me, if you are sure that everything that is
contained in all possible implementations of Schema is immutable (ie never
changes at runtime), and all the fields of said implementations are final, then
yes, it should be fine.
it is probably safer/easier to just make the field volatile though. i would
think that the performance difference would be negligible for nearly all use
cases.
Original comment by [email protected]
on 28 Jan 2011 at 4:04
from protostuff-googlecode-exported.
" if you are sure that everything that is contained in all possible
implementations of Schema is immutable"
Well if a user registers a custom schema for a class and its not immutable,
then houston will have a problem :-)
So if its better to be safe than sorry, I've no problem marking all the lazy
loaders all volatile.
Original comment by [email protected]
on 28 Jan 2011 at 8:41
from protostuff-googlecode-exported.
On second thought, the registered schemas are non-lazy.
Here's a single vulnerability:
When lazy loaded and protostuff identifies that the object is a message, it
will use the schema of that message.
If the schema of that message was hand-written, and it is not immutable,
lazy-load without volatile will fail at that point.
Original comment by [email protected]
on 28 Jan 2011 at 8:55
from protostuff-googlecode-exported.
i think by and large any time you use DCL you should really use volatile on the
guarded variable...trying to optimize b/c of immutability really is a
minefield, and imo in all real-world cases of no tangible benefit. there are
those that say even DCL is an optimization too far, ie uncontended
synchronization is very cheap, almost as cheap as a volatile read:
http://www.ibm.com/developerworks/library/j-jtp03304/?ca=dnt-513
Original comment by [email protected]
on 31 Jan 2011 at 10:23
from protostuff-googlecode-exported.
every DCL now marked volatile.
@rev 1219
Original comment by [email protected]
on 1 Feb 2011 at 11:35
- Changed state: Fixed
from protostuff-googlecode-exported.
Related Issues (20)
- Would like support for repeated accessors with out "List" appeneded
- Enter one-line summary HOT 2
- getSchema() of java.util.Properties fails HOT 2
- optimize xml format
- Enum alias support
- YamlOutput bug on repeated message fields HOT 1
- Deserializing a message which is protostuff-runtime serialized and has custom class as field HOT 3
- Visual disturbance of @Deprecated annotation HOT 12
- Support for newing object instances on Android 4.3+ devices HOT 2
- ConcurrentLinkedDeque support HOT 1
- Produces uncompilable Java when a field is called "default" HOT 4
- 1.0.7 Build error: ProtoParserTest fails HOT 2
- protostuff-parser and protostuff-compiler disagree on required version of antlr
- Optimize ProtobufOuput for small nested messages (max size of 127) HOT 1
- How can I serialize a negative int32 to the protobuf format using zigzag encoding? HOT 2
- How to Ignore Array of Null Values in JSON
- enums_by_name does not seem to be working using maven plugin
- The value of DataInput.readByte() should not be eof-checked since that method throws EOFException HOT 1
- Wrong output path is generated in Windows for .java files HOT 3
- Unable to parse proto enum containing hex constants HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protostuff-googlecode-exported.