Skip to content

Commit

Permalink
Limit generated reification to 10 since accessors etc are static.
Browse files Browse the repository at this point in the history
Without this we would generate N-wide objects, but never use more
than the first ten fields.

This also fixes an indy issue because we constructed the base
VariableAccessor as the fallback, which does not have the
"checked" set and get logic indy expected to bind to.
headius committed May 23, 2018
1 parent d6b5623 commit 4e1c9dd
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ReifiedRubyObject.java
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@
* the overhead of creating and managing a separate array and reference.
*/
public abstract class ReifiedRubyObject extends RubyObject {
public static int REIFIED_MAX = 10;

public ReifiedRubyObject(Ruby runtime, RubyClass metaClass) {
super(runtime, metaClass);
}
Original file line number Diff line number Diff line change
@@ -609,7 +609,20 @@ synchronized final VariableAccessor allocateVariableAccessorForVar(String name,
newVariableAccessor = new VariableAccessorVar9(realClass, name, newIndex, id);
break;
default:
newVariableAccessor = new VariableAccessor(realClass, name, newIndex, id);
if (Options.VOLATILE_VARIABLES.load()) {
if (UnsafeHolder.U == null) {
newVariableAccessor = new SynchronizedVariableAccessor(realClass, name, newIndex, id);
} else {
newVariableAccessor = new StampedVariableAccessor(realClass, name, newIndex, id);
}
} else {
if (UnsafeHolder.U == null) {
newVariableAccessor = new NonvolatileVariableAccessor(realClass, name, newIndex, id);
} else {
// We still need safe updating of the vartable, so we fall back on sync here too.
newVariableAccessor = new StampedVariableAccessor(realClass, name, newIndex, id);
}
}
}

final String[] newVariableNames = new String[newIndex + 1];
Original file line number Diff line number Diff line change
@@ -121,7 +121,9 @@ private static Class generateInternal(RubyClass klass, final Set<String> names,
klass.getVariableTableManager().getVariableAccessorForVar(name, i);
i++;
}
final int count = i;

// until variable accessors are generated as well, we limit generation to statically available size
final int count = Math.min(i, ReifiedRubyObject.REIFIED_MAX);

// create a new one
final String[] newFields = varList(count);

0 comments on commit 4e1c9dd

Please sign in to comment.