Skip to content

Commit 78da7ae

Browse files
committed
Eliminate access of RubyBasicObject flags
Global object flags will become private in a future JRuby version, to allow replacing them with smaller and more localized flags in each type of object. This patch moves the StringIO-specific flags into the StringIO object and eliminates all accesses of the global RubyBasicObject.flags.
1 parent c3474bf commit 78da7ae

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ext/java/org/jruby/ext/stringio/StringIO.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static class StringIOData {
9292
volatile Object owner;
9393
}
9494
private StringIOData ptr;
95+
private byte flags;
9596

9697
// MRI: get_strio, StringIO macro
9798
private StringIOData getPtr() {
@@ -103,9 +104,9 @@ private StringIOData getPtr() {
103104
private static final String
104105
STRINGIO_VERSION = "3.1.9";
105106

106-
private static final int STRIO_READABLE = ObjectFlags.registry.newFlag(StringIO.class);
107-
private static final int STRIO_WRITABLE = ObjectFlags.registry.newFlag(StringIO.class);
108-
private static final int STRIO_READWRITE = (STRIO_READABLE | STRIO_WRITABLE);
107+
private static final byte STRIO_READABLE = 1;
108+
private static final byte STRIO_WRITABLE = 2;
109+
private static final byte STRIO_READWRITE = (STRIO_READABLE | STRIO_WRITABLE);
109110

110111
private static final AtomicReferenceFieldUpdater<StringIOData, Object> LOCKED_UPDATER = AtomicReferenceFieldUpdater.newUpdater(StringIOData.class, Object.class, "owner");
111112

@@ -412,7 +413,7 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) {
412413
if (this == otherIO) return this;
413414

414415
ptr = otherIO.getPtr();
415-
flags = flags & ~STRIO_READWRITE | otherIO.flags & STRIO_READWRITE;
416+
flags = (byte) (flags & ~STRIO_READWRITE | otherIO.flags & STRIO_READWRITE);
416417

417418
return this;
418419
}
@@ -483,7 +484,7 @@ public IRubyObject close_read(ThreadContext context) {
483484
}
484485
int flags = this.flags;
485486
if ( ( flags & STRIO_READABLE ) != 0 ) {
486-
this.flags = flags & ~STRIO_READABLE;
487+
this.flags = (byte) (flags & ~STRIO_READABLE);
487488
}
488489
return context.nil;
489490
}
@@ -503,7 +504,7 @@ public IRubyObject close_write(ThreadContext context) {
503504
}
504505
int flags = this.flags;
505506
if ( ( flags & STRIO_WRITABLE ) != 0 ) {
506-
this.flags = flags & ~STRIO_WRITABLE;
507+
this.flags = (byte) (flags & ~STRIO_WRITABLE);
507508
}
508509
return context.nil;
509510
}

0 commit comments

Comments
 (0)