Top Description Fields Constructors Methods
org.jruby.ir.operands

public abstract Class ImmutableLiteral<T>

extends Operand
Class Inheritance
Known Direct Subclasses
org.jruby.ir.operands.Nil, org.jruby.ir.operands.NullBlock, org.jruby.ir.operands.Range, org.jruby.ir.operands.Rational, org.jruby.ir.operands.Regexp, org.jruby.ir.operands.Symbol, org.jruby.ir.operands.SymbolProc, org.jruby.ir.operands.UnboxedBoolean, org.jruby.ir.operands.UnboxedFixnum, org.jruby.ir.operands.UnboxedFloat, org.jruby.ir.operands.Integer, org.jruby.ir.operands.Bignum, org.jruby.ir.operands.Boolean, org.jruby.ir.operands.Complex, org.jruby.ir.operands.Fixnum, org.jruby.ir.operands.Float, org.jruby.ir.operands.FrozenString
Type Parameters
<T>
type of immutable literal
Imports
org.jruby.ir.transformations.inlining.CloneInfo, org.jruby.parser.StaticScope, org.jruby.runtime.DynamicScope, .ThreadContext, org.jruby.runtime.builtin.IRubyObject, java.util.List

Operands extending this type can make a reasonable assumption of immutability. In Ruby, almost nothing is truly immutable (set_instance_var) but for the sake of our compiler, we can assume the basic behavior will continue to work unchanged (the value of an instance of fixnum 3 will remain 3). Knowing that we have a literal which will not change can be used for optimizations like constant propagation. ENEBO: This cachedObject thing obviously cannot be used from multiple threads without some safety being added. This probably also is not the fastest code, but it is very simple. It would be really nice to make this side-effect free as well, but this is difficult without adding a level of indirection or pre-caching each value we encounter during construction.

Field Summary

Modifier and TypeField and Description
private T
Inherited from org.jruby.ir.operands.Operand:
EMPTY_ARRAY

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addUsedVariables(List<Variable> l)

Implements abstract org.jruby.ir.operands.Operand.addUsedVariables.

Append the list of variables used in this operand to the input list -- force every operand to implement this because a missing implementation can cause bad failures.

public T
cachedObject(ThreadContext context)

Returns the cached object.

public boolean
canCopyPropagate()

Overrides org.jruby.ir.operands.Operand.canCopyPropagate.

Can we replace every use of a variable 'v' that contains the value of this operand with the operand itself?

public Operand
public abstract T
createCacheObject(ThreadContext context)

Implementing class is responsible for constructing the cached value.

public boolean
hasKnownValue()

Overrides org.jruby.ir.operands.Operand.hasKnownValue.

Do we know the value of this operand at compile-time?

public boolean
isCached()

Has this object already been cached?

public T
retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp)

Overrides org.jruby.ir.operands.Operand.retrieve.

retrieve the live value represented by this immutable literal.

Inherited from org.jruby.ir.operands.Operand:
encodegetOperandTypegetSimplifiedOperandgetValueisFalseyImmediateisTruthyImmediatevisit

Field Detail

cachedObjectback to summary
private T cachedObject

Constructor Detail

ImmutableLiteralback to summary
public ImmutableLiteral()

Method Detail

addUsedVariablesback to summary
public void addUsedVariables(List<Variable> l)

Implements abstract org.jruby.ir.operands.Operand.addUsedVariables.

Doc from org.jruby.ir.operands.Operand.addUsedVariables.

Append the list of variables used in this operand to the input list -- force every operand to implement this because a missing implementation can cause bad failures.

Annotations
@Override
cachedObjectback to summary
public T cachedObject(ThreadContext context)

Returns the cached object. If not then it asks class to create an object to cache.

canCopyPropagateback to summary
public boolean canCopyPropagate()

Overrides org.jruby.ir.operands.Operand.canCopyPropagate.

Doc from org.jruby.ir.operands.Operand.canCopyPropagate.

Can we replace every use of a variable 'v' that contains the value of this operand with the operand itself? This takes importance when there are at least two uses of 'v' within this scope. Ex: v = [1,2,3]; x = v; y = v In this case, we cannot replace the occurrences of 'v' because we would then get x = [1,2,3]; y = [1,2,3] which would then result in two different array objects being constructed instead of a single one.

Returns:boolean

true if it is safe to copy-propagate the operand.

Annotations
@Override
cloneForInliningback to summary
public Operand cloneForInlining(CloneInfo ii)

Implements abstract org.jruby.ir.operands.Operand.cloneForInlining.

Annotations
@Override
createCacheObjectback to summary
public abstract T createCacheObject(ThreadContext context)

Implementing class is responsible for constructing the cached value.

hasKnownValueback to summary
public boolean hasKnownValue()

Overrides org.jruby.ir.operands.Operand.hasKnownValue.

Doc from org.jruby.ir.operands.Operand.hasKnownValue.

Do we know the value of this operand at compile-time? If we do then it may be possible to constant propagate (one case: We also know it is also an ImmutableLiteral).

Returns:boolean

true if a known compile-time value.

Annotations
@Override
isCachedback to summary
public boolean isCached()

Has this object already been cached?

retrieveback to summary
public T retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp)

Overrides org.jruby.ir.operands.Operand.retrieve.

retrieve the live value represented by this immutable literal. An interesting property of knowing something cannot change at compile time is that all information necessary to construct it is also known at compile time. We don't pre-create these since we don't want to assume the cost of constructing literals which may never be used.

Annotations
@Override