Project

General

Profile

Feature #1752

eliminate statics/singleton patterns in all TRPL worker classes and other dependent Java code

Added by Greg Shah over 13 years ago. Updated about 1 year ago.

Status:
WIP
Priority:
Normal
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
80.00 h
billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:

Related issues

Related to TRPL - Feature #3211: implement multi-threaded pattern engine and rework the ConversionDriver to leverage it Review

History

#1 Updated by Greg Shah over 13 years ago

  • Target version set to Code Improvements

#2 Updated by Greg Shah over 9 years ago

  • Target version changed from Code Improvements to TRPL 2.0
  • Estimated time changed from 40.00 to 80.00

#3 Updated by Greg Shah about 1 year ago

  • Related to Feature #3211: implement multi-threaded pattern engine and rework the ConversionDriver to leverage it added

#4 Updated by Greg Shah about 1 year ago

  • Subject changed from eliminate statics/singleton patterns in pattern engine/symbol resolver and other related classes to eliminate statics/singleton patterns in all TRPL worker classes and other dependent Java code

#5 Updated by Greg Shah about 1 year ago

  • Target version deleted (TRPL 2.0)
  • Assignee set to Octavian Adrian Gavril

#6 Updated by Octavian Adrian Gavril about 1 year ago

  • Status changed from New to WIP

#7 Updated by Octavian Adrian Gavril about 1 year ago

Here is a full list with worker classes used in TRPL:
  1. com.goldencode.p2j.schema.ImportWorker$SqlRecordLoader
  2. com.goldencode.p2j.convert.NameMappingWorker$ProgramInfo
  3. com.goldencode.p2j.convert.NameMappingWorker$MethodInfo
  4. com.goldencode.p2j.uast.CallGraphWorker$CallSiteHint
  5. com.goldencode.p2j.convert.BufferScopeWorker
  6. com.goldencode.p2j.convert.DatabaseReferenceWorker
  7. com.goldencode.p2j.convert.ExpressionConversionWorker
  8. com.goldencode.p2j.convert.I18nWorker
  9. com.goldencode.p2j.convert.IndexSelectionWorker
  10. com.goldencode.p2j.convert.NameConverterWorker
  11. com.goldencode.p2j.convert.NameMappingWorker
  12. com.goldencode.p2j.convert.UnreachableCodeWorker
  13. com.goldencode.p2j.pattern.FileOperationsWorker
  14. com.goldencode.p2j.pattern.TemplateWorker
  15. com.goldencode.p2j.persist.orm.DDLGeneratorWorker
  16. com.goldencode.p2j.preproc.PreprocessorHintsWorker
  17. com.goldencode.p2j.report.ReportWorker
  18. com.goldencode.p2j.schema.DataModelWorker
  19. com.goldencode.p2j.schema.DmoAsmWorker
  20. com.goldencode.p2j.schema.ImportWorker
  21. com.goldencode.p2j.schema.P2OAccessWorker
  22. com.goldencode.p2j.schema.SchemaWorker
  23. com.goldencode.p2j.uast.CallGraphWorker
  24. com.goldencode.p2j.uast.JavaPatternWorker
  25. com.goldencode.p2j.uast.ProgressPatternWorker
  26. com.goldencode.p2j.uast.UastHintsWorker
  27. com.goldencode.p2j.xml.XmlPatternWorker

#8 Updated by Constantin Asofiei about 1 year ago

If you look at DataModelWorker, you will see the static state is in a WorkArea class, to be context-local. This (and other pattern classes) were changed like this, to allow runtime conversion of queries; other classes which are not yet changed I think should move to the same context-local approach.

#9 Updated by Octavian Adrian Gavril about 1 year ago

Constantin Asofiei wrote:

If you look at DataModelWorker, you will see the static state is in a WorkArea class, to be context-local. This (and other pattern classes) were changed like this, to allow runtime conversion of queries; other classes which are not yet changed I think should move to the same context-local approach.

Got it. So, I need to move all the static variables (shared data) into a WorkArea inner class that ensures thread safety for all the workers used in TRPL.

#10 Updated by Octavian Adrian Gavril about 1 year ago

Should static methods be kept or make them non-static and use them through a class instance?
DataModelWorker:

-            XmlPatternWorker.createAst(XmlTokenTypes.CONTENT, schema + ".impl", elAttr);
+            context.get().xpw.createAst(XmlTokenTypes.CONTENT, schema + ".impl", elAttr);
          }

          this.schemaElem = schemaElem;
@@ -1101,7 +1102,7 @@
             while (attr != null)
             {
                String key = attr.getText();
-               String value = XmlPatternWorker.getAttributeValue(attrs, key);
+               String value = context.get().xpw.getAttributeValue(attrs, key);

                info.putAttribute(key, value);

@@ -1342,5 +1343,7 @@
    private static class WorkArea
    {
       /** Root of the target tree currently being processed (created). */
       private DataModelAst root = null;
+
+      private final XmlPatternWorker xpw = new XmlPatternWorker();
    }
 }

#11 Updated by Greg Shah about 1 year ago

There is nothing intrinsically unsafe with static methods. Any state they access will need to be context local OR synchronized/protected to be thread-safe.

#12 Updated by Octavian Adrian Gavril about 1 year ago

I went through all the workers listed above and checked where the variables are good to store in the context-local. I ignored all the constants or immutable lists, as they are populated in a static block and then just referenced. Most of the workers were in this situation, having logs or constants. I made these changes in the task branch 1752a/15886.

Also available in: Atom PDF