Class Bytecode

  • All Implemented Interfaces:
    Serializable, Cloneable

    public final class Bytecode
    extends Object
    implements Cloneable, Serializable
    When a TraversalSource is manipulated and then a Traversal is spawned and mutated, a language agnostic representation of those mutations is recorded in a bytecode instance. Bytecode is simply a list of ordered instructions where an instruction is a string operator and a (flattened) array of arguments. Bytecode is used by Translator instances which are able to translate a traversal in one language to another by analyzing the bytecode as opposed to the Java traversal object representation on heap.

    Bytecode can be serialized between environments and machines by way of a GraphSON representation. Thus, Gremlin-Python can create bytecode in Python and ship it to Gremlin-Java for evaluation in Java.

    Marko A. Rodriguez (
    See Also:
    Serialized Form
    • Constructor Detail

      • Bytecode

        public Bytecode()
    • Method Detail

      • addSource

        public void addSource​(String sourceName,
                              Object... arguments)
        Add a TraversalSource instruction to the bytecode.
        sourceName - the traversal source method name (e.g. withSack())
        arguments - the traversal source method arguments
      • addStep

        public void addStep​(String stepName,
                            Object... arguments)
        Add a Traversal instruction to the bytecode.
        stepName - the traversal method name (e.g. out())
        arguments - the traversal method arguments
      • getStepInstructions

        public List<Bytecode.Instruction> getStepInstructions()
        Get the Traversal instructions associated with this bytecode.
        an iterable of instructions
      • getInstructions

        public Iterable<Bytecode.Instruction> getInstructions()
        Get both the TraversalSource and Traversal instructions of this bytecode. The traversal source instructions are provided prior to the traversal instructions.
        an interable of all the instructions in this bytecode
      • getBindings

        public Map<String,​Object> getBindings()
        Get all the bindings (in a nested, recursive manner) from all the arguments of all the instructions of this bytecode.
        a map of string variable and object value bindings
      • isEmpty

        public boolean isEmpty()
      • hashCode

        public int hashCode()
        hashCode in class Object