From a538c4d829dd98427a85c8720a05cb75085f577b Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 1 Dec 2025 10:46:29 -0600 Subject: [PATCH] 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. --- ext/java/org/jruby/ext/stringio/StringIO.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/java/org/jruby/ext/stringio/StringIO.java b/ext/java/org/jruby/ext/stringio/StringIO.java index 13329a0..43abb71 100644 --- a/ext/java/org/jruby/ext/stringio/StringIO.java +++ b/ext/java/org/jruby/ext/stringio/StringIO.java @@ -92,6 +92,7 @@ static class StringIOData { volatile Object owner; } private StringIOData ptr; + private byte flags; // MRI: get_strio, StringIO macro private StringIOData getPtr() { @@ -103,9 +104,9 @@ private StringIOData getPtr() { private static final String STRINGIO_VERSION = "3.1.8"; - private static final int STRIO_READABLE = ObjectFlags.registry.newFlag(StringIO.class); - private static final int STRIO_WRITABLE = ObjectFlags.registry.newFlag(StringIO.class); - private static final int STRIO_READWRITE = (STRIO_READABLE | STRIO_WRITABLE); + private static final byte STRIO_READABLE = 1; + private static final byte STRIO_WRITABLE = 2; + private static final byte STRIO_READWRITE = (STRIO_READABLE | STRIO_WRITABLE); private static final AtomicReferenceFieldUpdater LOCKED_UPDATER = AtomicReferenceFieldUpdater.newUpdater(StringIOData.class, Object.class, "owner"); @@ -412,7 +413,7 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) { if (this == otherIO) return this; ptr = otherIO.getPtr(); - flags = flags & ~STRIO_READWRITE | otherIO.flags & STRIO_READWRITE; + flags = (byte) (flags & ~STRIO_READWRITE | otherIO.flags & STRIO_READWRITE); return this; } @@ -483,7 +484,7 @@ public IRubyObject close_read(ThreadContext context) { } int flags = this.flags; if ( ( flags & STRIO_READABLE ) != 0 ) { - this.flags = flags & ~STRIO_READABLE; + this.flags = (byte) (flags & ~STRIO_READABLE); } return context.nil; } @@ -503,7 +504,7 @@ public IRubyObject close_write(ThreadContext context) { } int flags = this.flags; if ( ( flags & STRIO_WRITABLE ) != 0 ) { - this.flags = flags & ~STRIO_WRITABLE; + this.flags = (byte) (flags & ~STRIO_WRITABLE); } return context.nil; }