6161import org .jruby .runtime .ivars .VariableTableManager ;
6262import org .jruby .runtime .marshal .CoreObjectType ;
6363import org .jruby .util .ArraySupport ;
64- import org .jruby .util .ByteList ;
6564import org .jruby .util .IdUtil ;
6665import org .jruby .util .TypeConverter ;
6766
@@ -168,7 +167,7 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
168167 protected transient RubyClass metaClass ;
169168
170169 /** object flags */
171- protected int flags ;
170+ protected byte flags ;
172171
173172 /** variable table, lazily allocated as needed (if needed) */
174173 public transient Object [] varTable ;
@@ -182,8 +181,15 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
182181 */
183182 public static final String ERR_INSECURE_SET_INST_VAR = "Insecure: can't modify instance variable" ;
184183
184+ static final byte FALSE = 0b00000001;
185+ static final byte NIL = 0b00000010;
186+ static final byte FROZEN = 0b00000100;
187+
188+ @ Deprecated (since = "10.0.3.0" )
185189 public static final int ALL_F = -1 ;
186- public static final int FALSE_F = ObjectFlags .FALSE_F ;
190+ /** @deprecated external access to global object flags is going away */
191+ @ Deprecated (since = "10.0.3.0" )
192+ public static final int FALSE_F = FALSE ;
187193 /**
188194 * This flag is a bit funny. It's used to denote that this value
189195 * is nil. It's a bit counterintuitive for a Java programmer to
@@ -193,8 +199,12 @@ public class RubyBasicObject implements Cloneable, IRubyObject, Serializable, Co
193199 * that it gives a good speed boost to make it monomorphic and
194200 * final. It turns out using a flag for this actually gives us
195201 * better performance than having a polymorphic {@link #isNil()} method.
202+ *
203+ * @deprecated external access to global object flags is going away
196204 */
197- public static final int NIL_F = ObjectFlags .NIL_F ;
205+ @ Deprecated (since = "10.0.3.0" )
206+ public static final int NIL_F = NIL ;
207+ @ Deprecated (since = "10.0.3.0" )
198208 public static final int FROZEN_F = ObjectFlags .FROZEN_F ;
199209
200210 /**
@@ -310,40 +320,28 @@ protected final void testFrozen() {
310320 }
311321
312322 /**
313- * Sets or unsets a flag on this object. The only flags that are
314- * guaranteed to be valid to use as the first argument is:
315- *
316- * <ul>
317- * <li>{@link #FALSE_F}</li>
318- * <li>{@link #NIL_F}</li>
319- * <li>{@link #FROZEN_F}</li>
320- * </ul>
321- *
322- * @param flag the actual flag to set or unset.
323- * @param set if true, the flag will be set, if false, the flag will be unset.
323+ * @deprecated external access to global object flags is going away
324324 */
325+ @ Deprecated (since = "10.0.3.0" )
325326 public final void setFlag (int flag , boolean set ) {
326- if (set ) {
327+ if (flag == FROZEN ) {
328+ setFrozen (set );
329+ } else if (set ) {
327330 flags |= flag ;
328331 } else {
329332 flags &= ~flag ;
330333 }
331334 }
332335
333336 /**
334- * Get the value of a custom flag on this object. The only
335- * guaranteed flags that can be sent in to this method is:
336- *
337- * <ul>
338- * <li>{@link #FALSE_F}</li>
339- * <li>{@link #NIL_F}</li>
340- * <li>{@link #FROZEN_F}</li>
341- * </ul>
342- *
343- * @param flag the flag to get
344- * @return true if the flag is set, false otherwise
337+ * @deprecated external access to global object flags is going away
345338 */
339+ @ Deprecated (since = "10.0.3.0" )
346340 public final boolean getFlag (int flag ) {
341+ if (flag == FROZEN ) {
342+ return isFrozen ();
343+ }
344+
347345 return (flags & flag ) != 0 ;
348346 }
349347
@@ -413,54 +411,55 @@ public final IRubyObject callMethod(ThreadContext context, String name, IRubyObj
413411 }
414412
415413 /**
416- * Does this object represent nil? See the docs for the {@link
417- * #NIL_F} flag for more information.
414+ * Does this object represent nil?
415+ *
416+ * @return true if nil
418417 */
419418 @ Override
420419 public final boolean isNil () {
421- return (flags & NIL_F ) != 0 ;
420+ return (flags & NIL ) != 0 ;
422421 }
423422
424423 /**
425- * Is this value a truthy value or not? Based on the {@link #FALSE_F} flag.
426- * @return true it truthy
424+ * Is this value a truthy value or not?
425+ *
426+ * @return true if truthy
427427 */
428428 @ Override
429429 public final boolean isTrue () {
430- return (flags & FALSE_F ) == 0 ;
430+ return (flags & FALSE ) == 0 ;
431431 }
432432
433433 /**
434- * Is this value a falsey value or not? Based on the {@link #FALSE_F} flag.
435- * @return true is false
434+ * Is this value a falsey value or not?
435+ *
436+ * @return true if falsey
436437 */
437438 public final boolean isFalse () {
438- return (flags & FALSE_F ) != 0 ;
439+ return (flags & FALSE ) != 0 ;
439440 }
440441
441- /**
442- * Is this value frozen or not? Shortcut for doing
443- * getFlag(FROZEN_F).
442+ /** whether the object has been frozen */ /**
443+ * Is this value frozen or not?
444444 *
445445 * @return true if this object is frozen, false otherwise
446446 */
447447 @ Override
448448 public boolean isFrozen () {
449- return (flags & FROZEN_F ) != 0 ;
449+ return (flags & FROZEN ) != 0 ;
450450 }
451451
452452 /**
453- * Sets whether this object is frozen or not. Shortcut for doing
454- * setFlag(FROZEN_F, frozen).
453+ * Sets whether this object is frozen or not.
455454 *
456455 * @param frozen should this object be frozen?
457456 */
458457 @ Override
459458 public void setFrozen (boolean frozen ) {
460459 if (frozen ) {
461- flags |= FROZEN_F ;
460+ flags |= FROZEN ;
462461 } else {
463- flags &= ~FROZEN_F ;
462+ flags &= ~FROZEN ;
464463 }
465464 }
466465
0 commit comments