Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

get rid of AtomicIntegerFieldUpdater, it performs class inheritance

checks checks. bad for opto.
  • Loading branch information...
commit 68d51b28e28d1af2fbb341421b4baac32d6a87f8 1 parent bc865bc
the8472 authored

Showing 1 changed file with 8 additions and 25 deletions. Show diff stats Hide diff stats

  1. +8 25 src/org/jruby/RubyBasicObject.java
33 src/org/jruby/RubyBasicObject.java
@@ -124,6 +124,7 @@
124 124 private transient volatile int varTableStamp;
125 125
126 126 private static final long VAR_TABLE_OFFSET = UnsafeHolder.fieldOffset(RubyBasicObject.class, "varTable");
  127 + private static final long STAMP_OFFSET = UnsafeHolder.fieldOffset(RubyBasicObject.class, "varTableStamp");
127 128
128 129 /**
129 130 * The error message used when some one tries to modify an
@@ -1195,24 +1196,6 @@ public void removeFinalizers() {
1195 1196 return varTable;
1196 1197 }
1197 1198
1198   - private static final AtomicIntegerFieldUpdater STAMP_UPDATER;
1199   -
1200   - static {
1201   - AtomicIntegerFieldUpdater updater = null;
1202   - try {
1203   - updater = AtomicIntegerFieldUpdater.newUpdater(RubyBasicObject.class, "varTableStamp");
1204   - } catch (RuntimeException re) {
1205   - if (re.getCause() instanceof AccessControlException) {
1206   - // security prevented creation; fall back on synchronized assignment
1207   - } else {
1208   - throw re;
1209   - }
1210   - }
1211   - STAMP_UPDATER = updater;
1212   - }
1213   -
1214   -
1215   -
1216 1199 public Object getVariable(int index) {
1217 1200 Object[] ivarTable;
1218 1201 if (index < 0 || (ivarTable = getVariableTableForRead()) == null) return null;
@@ -1254,7 +1237,7 @@ private void setVariableStamped(int index, Object value) {
1254 1237 for(;;) {
1255 1238 int currentStamp = varTableStamp;
1256 1239 // spin-wait if odd
1257   - if((currentStamp & 0x01) == 1)
  1240 + if((currentStamp & 0x01) != 0)
1258 1241 continue;
1259 1242
1260 1243 Object[] currentTable = (Object[]) UnsafeHolder.U.getObjectVolatile(this, VAR_TABLE_OFFSET);
@@ -1262,7 +1245,7 @@ private void setVariableStamped(int index, Object value) {
1262 1245 if(currentTable == null || index >= currentTable.length)
1263 1246 {
1264 1247 // try to acquire exclusive access to the varTable field
1265   - if(!STAMP_UPDATER.compareAndSet(this, currentStamp, ++currentStamp))
  1248 + if(!UnsafeHolder.U.compareAndSwapInt(this, STAMP_OFFSET, currentStamp, ++currentStamp))
1266 1249 continue;
1267 1250
1268 1251 Object[] newTable = new Object[getMetaClass().getRealClass().getVariableTableSizeWithExtras()];
@@ -1272,7 +1255,7 @@ private void setVariableStamped(int index, Object value) {
1272 1255 UnsafeHolder.U.putOrderedObject(this, VAR_TABLE_OFFSET, newTable);
1273 1256
1274 1257 // release exclusive access
1275   - STAMP_UPDATER.set(this, ++currentStamp);
  1258 + varTableStamp = currentStamp + 1;
1276 1259 } else {
1277 1260 // shared access to varTable field.
1278 1261
@@ -1285,7 +1268,7 @@ private void setVariableStamped(int index, Object value) {
1285 1268 }
1286 1269
1287 1270 // validate stamp. redo on concurrent modification
1288   - if(STAMP_UPDATER.get(this) != currentStamp)
  1271 + if(varTableStamp != currentStamp)
1289 1272 continue;
1290 1273
1291 1274 }
@@ -1496,13 +1479,13 @@ public void syncVariables(IRubyObject other) {
1496 1479 if((oldStamp & 0x01) == 1)
1497 1480 continue;
1498 1481 // acquire exclusive write mode
1499   - if(!STAMP_UPDATER.compareAndSet(this, oldStamp, ++oldStamp))
  1482 + if(!UnsafeHolder.U.compareAndSwapInt(this, STAMP_OFFSET, oldStamp, ++oldStamp))
1500 1483 continue;
1501 1484
1502 1485 UnsafeHolder.U.putOrderedObject(this, VAR_TABLE_OFFSET, makeSyncedTable(otherVars, idIndex));
1503 1486
1504 1487 // release write mode
1505   - STAMP_UPDATER.set(this, ++oldStamp);
  1488 + varTableStamp = oldStamp+1;
1506 1489 break;
1507 1490 }
1508 1491
@@ -2925,7 +2908,7 @@ public IRubyObject instance_variable_get(ThreadContext context, IRubyObject name
2925 2908 * fred.inspect #=> "#<Fred:0x401b3da8 @a=\"dog\", @b=99, @c=\"cat\">"
2926 2909 */
2927 2910 public IRubyObject instance_variable_set(IRubyObject name, IRubyObject value) {
2928   - ensureInstanceVariablesSettable();
  2911 + // no need to check for ensureInstanceVariablesSettable() here, that'll happen downstream in setVariable
2929 2912 return (IRubyObject)variableTableStore(validateInstanceVariable(name.asJavaString()), value);
2930 2913 }
2931 2914

0 comments on commit 68d51b2

Please sign in to comment.
Something went wrong with that request. Please try again.