Project

General

Profile

cache_internal_entries.diff

Hynek Cihlar, 05/04/2023 09:37 AM

Download (5.81 KB)

View differences:

src/com/goldencode/p2j/util/ControlFlowOps.java 2023-05-04 13:39:44 +0000
4785 4785
      return true;
4786 4786
   }
4787 4787

  
4788
   public static class ObjectInternalEntryCacheKey
4789
   {
4790
      private Class aClass;
4791
      private String modes;
4792
      private Class[] argsClasses;
4793
      private int hashCode;
4794

  
4795
      public ObjectInternalEntryCacheKey(Class aClass, String modes, Class[] argsClasses)
4796
      {
4797
         this.aClass = aClass;
4798
         this.modes = modes;
4799
         this.argsClasses = argsClasses;
4800

  
4801
         int result = Objects.hash(aClass, modes);
4802
         result = 31 * result + Arrays.hashCode(argsClasses);
4803
         this.hashCode = result;
4804
      }
4805

  
4806
      @Override
4807
      public boolean equals(Object o)
4808
      {
4809
         if (this == o)
4810
         {
4811
            return true;
4812
         }
4813
         if (o == null)
4814
         {
4815
            return false;
4816
         }
4817
         ObjectInternalEntryCacheKey that = (ObjectInternalEntryCacheKey) o;
4818
         return Objects.equals(aClass, that.aClass) &&
4819
            Objects.equals(modes, that.modes) &&
4820
            Arrays.equals(argsClasses, that.argsClasses);
4821
      }
4822

  
4823
      @Override
4824
      public int hashCode()
4825
      {
4826
         return hashCode;
4827
      }
4828

  
4829
      @Override
4830
      public String toString()
4831
      {
4832
         return "ObjectInternalEntryCacheKey{" +
4833
            "aClass=" + aClass +
4834
            ", modes='" + modes + '\'' +
4835
            ", argsClasses=" + Arrays.toString(argsClasses) +
4836
            '}';
4837
      }
4838
   }
4839

  
4788 4840
   /**
4789 4841
    * Given a legacy class instance, execute the initialization methods.  These are comprised from
4790 4842
    * the synthetic execute methods (for all super-classes), and the synthetic constructor method 
......
4814 4866
      wa.pm.addProcedure(phandle, name, true);
4815 4867
      
4816 4868
      BufferManager.get().resolvePendingBufferClasses(referent);
4817
      
4818
      List<InternalEntry> ctors = SourceNameMapper.getConstructors((Class) referent.getClass());
4819
      
4820
      InternalEntry ie = resolveLegacyEntry(wa, false, referent.getClass(), name, null, modes, ctors, args);
4869

  
4870
      Class refClass = referent.getClass();
4871
      List<InternalEntry> ctors = SourceNameMapper.getConstructors(refClass);
4872

  
4873
      Class[] argsClasses = new Class[args == null ? 0 : args.length];
4874
      for (int i = 0; i < argsClasses.length; i++)
4875
      {
4876
         argsClasses[i] = args[i].getClass();
4877
      }
4878

  
4879
      ObjectInternalEntryCacheKey key = new ObjectInternalEntryCacheKey(refClass, modes, argsClasses);
4880
      InternalEntry ie = wa.cachedObjectIEntries.get(key);
4881
      System.out.println(key + " -> " + ie);
4821 4882
      if (ie == null)
4822 4883
      {
4884
         ie = resolveLegacyEntry(wa, false, refClass, name, null, modes, ctors, args);
4885
         if (ie == null)
4886
         {
4887
            ie = InternalEntry.NULL;
4888
         }
4889
         wa.cachedObjectIEntries.put(key, ie);
4890
         System.out.println(key + " put " + ie);
4891
      }
4892
      if (ie == InternalEntry.NULL)
4893
      {
4823 4894
         // not found
4824 4895
         return false;
4825 4896
      }
......
4882 4953
            // use the method resolved after arg validation.
4883 4954
            ctorCaller.mthd = ie.getMethod();
4884 4955

  
4956
            InternalEntry finalIe = ie;
4885 4957
            Runnable push = () ->
4886 4958
            {
4887
               Class<?> def = ie.getMethod().getDeclaringClass();
4959
               Class<?> def = finalIe.getMethod().getDeclaringClass();
4888 4960
               wa.pm.pushCalleeInfo(def, false, referent, referent, "CONSTRUCTOR", relName, false, false);
4889 4961
            };
4890 4962

  
......
9040 9112

  
9041 9113
      /** Cached resolved procedure internal entries */
9042 9114
      private HashMap<InternalResolver.InternalEntryCacheKey, InternalEntry> cachedIEntries = new HashMap<>();
9115

  
9116
      private HashMap<ObjectInternalEntryCacheKey, InternalEntry> cachedObjectIEntries = new HashMap<>();
9043 9117
      
9044 9118
      private WorkArea()
9045 9119
      {
src/com/goldencode/p2j/util/InternalEntry.java 2023-05-04 13:39:44 +0000
108 108
 */
109 109
public class InternalEntry
110 110
{
111
   @Override
112
   public String toString()
113
   {
114
      return "InternalEntry{" +
115
         "pname='" + pname + '\'' +
116
         ", jname='" + jname + '\'' +
117
         ", type=" + type +
118
         ", signature='" + signature + '\'' +
119
         ", parameterModes='" + parameterModes + '\'' +
120
         ", isSuper=" + isSuper +
121
         ", inHandle=" + inHandle +
122
         ", isPrivate=" + isPrivate +
123
         ", extent=" + extent +
124
         ", method=" + method +
125
         ", libname='" + libname + '\'' +
126
         '}';
127
   }
128

  
111 129
   /** Type of internal entry */
112 130
   public static enum Type
113 131
   {
......
223 241
         return name;
224 242
      }
225 243
   };
226
   
244

  
245
   /** Represents null InternalEntry value */
246
   public static final InternalEntry NULL = new InternalEntry();
247

  
227 248
   public static enum SerializeMode {
228 249
      DEFAULT,
229 250
      VISIBLE,
......
307 328
    */
308 329
   private ExternalProgram extprog;
309 330

  
310
   /** Represents null InternalEntry value */
311
   public static final InternalEntry NULL = new InternalEntry();
312

  
313 331
   /**
314 332
    * Private constructor for the internal implementation.
315 333
    */
src/com/goldencode/p2j/util/SourceNameMapper.java 2023-05-04 13:39:44 +0000
1136 1136
    * 
1137 1137
    * @param    type
1138 1138
    *           The legacy class.
1139
    * @param    static_
1140
    *           If the static or instance constructors are required.
1141 1139
    */
1142 1140
   public static List<InternalEntry> getConstructors(Class<? extends _BaseObject_> type)
1143 1141
   {