Class JavaParsingAtomicArrayQueueGenerator

java.lang.Object
com.github.javaparser.ast.visitor.VoidVisitorAdapter<Void>
org.jctools.queues.atomic.JavaParsingAtomicQueueGenerator
org.jctools.queues.atomic.JavaParsingAtomicArrayQueueGenerator
All Implemented Interfaces:
com.github.javaparser.ast.visitor.VoidVisitor<Void>, JCToolsGenerator
Direct Known Subclasses:
JavaParsingAtomicUnpaddedArrayQueueGenerator

public class JavaParsingAtomicArrayQueueGenerator extends JavaParsingAtomicQueueGenerator
This generator takes in an JCTools 'ArrayQueue' Java source file and patches Unsafe accesses into atomic AtomicLongFieldUpdater. It outputs a Java source file with these patches.

An 'ArrayQueue' is one that is backed by a circular array and use a producerLimit and a consumerLimit field to track the positions of each.

  • Constructor Details

    • JavaParsingAtomicArrayQueueGenerator

      public JavaParsingAtomicArrayQueueGenerator(String sourceFileName)
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Throws:
      Exception
    • visit

      public void visit(com.github.javaparser.ast.body.ConstructorDeclaration n, Void arg)
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Void>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Void>
    • visit

      public void visit(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration node, Void arg)
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Void>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Void>
    • fieldUpdaterFieldName

      String fieldUpdaterFieldName(String fieldName)
      Specified by:
      fieldUpdaterFieldName in class JavaParsingAtomicQueueGenerator
    • processSpecialNodeTypes

      void processSpecialNodeTypes(com.github.javaparser.ast.nodeTypes.NodeWithType<?,com.github.javaparser.ast.type.Type> node, String name)
      Given a variable declaration of some sort, check it's name and type and if it looks like any of the key type changes between unsafe and atomic queues, perform the conversion to change it's type.
      Specified by:
      processSpecialNodeTypes in class JavaParsingAtomicQueueGenerator
    • patchMethodAsDeprecatedRedirector

      private void patchMethodAsDeprecatedRedirector(com.github.javaparser.ast.body.MethodDeclaration methodToPatch, String toMethodName, com.github.javaparser.ast.type.Type returnType, com.github.javaparser.ast.body.Parameter... parameters)
      Given a method declaration node this method will replace it's code and signature with code to redirect all calls to it to the newMethodName. Method signatures of both methods must match exactly.
    • patchAtomicFieldUpdaterAccessorMethods

      private void patchAtomicFieldUpdaterAccessorMethods(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration n)
      For each method accessor to a field, add in the calls necessary to AtomicFieldUpdaters. Only methods start with so/cas/sv/lv/lp followed by the field name are processed. Clearly lv, lp and sv are simple field accesses with only so and cas using the AtomicFieldUpdaters.
      Parameters:
      n - the AST node for the containing class
    • isLongArray

      private boolean isLongArray(com.github.javaparser.ast.type.Type in)
    • atomicRefArrayType

      private com.github.javaparser.ast.type.ClassOrInterfaceType atomicRefArrayType(com.github.javaparser.ast.type.ArrayType in)
    • atomicLongArrayType

      private com.github.javaparser.ast.type.ClassOrInterfaceType atomicLongArrayType()