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>

public final 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 an circular array and use a producerLimit and a consumerLimit field to track the positions of each.

  • Constructor Details

    • JavaParsingAtomicArrayQueueGenerator

      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>
    • translateQueueName

      String translateQueueName(String originalQueueName)
      Specified by:
      translateQueueName in class JavaParsingAtomicQueueGenerator
    • fieldUpdaterFieldName

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

      void organiseImports(com.github.javaparser.ast.CompilationUnit cu)
      Specified by:
      organiseImports 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
    • replaceParentClassesForAtomics

      private void replaceParentClassesForAtomics(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration n)
      Searches all extended or implemented super classes or interfaces for special classes that differ with the atomics version and replaces them with the appropriate class.
    • 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()