Permalink
Browse files

better separation of sync/unsafe code paths -> fix NPE

  • Loading branch information...
1 parent 5fdc963 commit 626a2404f77c792d221889439d7ee08151496cec @the8472 committed Jan 6, 2013
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/org/jruby/RubyBasicObject.java
@@ -1465,7 +1465,7 @@ public void syncVariables(IRubyObject other) {
if(UnsafeHolder.U == null)
{
synchronized (this) {
- varTable = makeSyncedTable(otherVars, idIndex);
+ varTable = makeSyncedTable(varTable, otherVars, idIndex);
}
} else {
for(;;) {
@@ -1477,7 +1477,10 @@ public void syncVariables(IRubyObject other) {
if(!UnsafeHolder.U.compareAndSwapInt(this, STAMP_OFFSET, oldStamp, ++oldStamp))
continue;
- UnsafeHolder.U.putOrderedObject(this, VAR_TABLE_OFFSET, makeSyncedTable(otherVars, idIndex));
+ Object[] currentTable = (Object[]) UnsafeHolder.U.getObjectVolatile(this, VAR_TABLE_OFFSET);
+ Object[] newTable = makeSyncedTable(currentTable,otherVars, idIndex);
+
+ UnsafeHolder.U.putOrderedObject(this, VAR_TABLE_OFFSET, newTable);
// release write mode
varTableStamp = oldStamp+1;
@@ -1503,9 +1506,7 @@ public void syncVariables(IRubyObject other) {
}
}
- private Object[] makeSyncedTable(Object[] otherTable, int objectIdIdx) {
- Object[] currentTable = (Object[]) UnsafeHolder.U.getObjectVolatile(this, VAR_TABLE_OFFSET);
-
+ private static Object[] makeSyncedTable(Object[] currentTable, Object[] otherTable, int objectIdIdx) {
if(currentTable == null || currentTable.length < otherTable.length)
currentTable = otherTable.clone();
else

0 comments on commit 626a240

Please sign in to comment.