jdk/src/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java
changeset 13610 28122b96858e
parent 13425 a8d96a0eda69
child 14089 0a41b980d62a
equal deleted inserted replaced
13460:c7aa5cca1c01 13610:28122b96858e
   183         className += sfx;
   183         className += sfx;
   184         return className;
   184         return className;
   185     }
   185     }
   186 
   186 
   187     class CpPatch {
   187     class CpPatch {
   188         int index;
   188         final int index;
   189         Object value;
   189         final String placeholder;
   190         CpPatch(int index, Object value) {
   190         final Object value;
       
   191         CpPatch(int index, String placeholder, Object value) {
   191             this.index = index;
   192             this.index = index;
       
   193             this.placeholder = placeholder;
   192             this.value = value;
   194             this.value = value;
       
   195         }
       
   196         public String toString() {
       
   197             return "CpPatch/index="+index+",placeholder="+placeholder+",value="+value;
   193         }
   198         }
   194     }
   199     }
   195 
   200 
   196     Map<Object, CpPatch> cpPatches = new HashMap<>();
   201     Map<Object, CpPatch> cpPatches = new HashMap<>();
   197 
   202 
   203         if (cpPatches.containsKey(cpPlaceholder)) {
   208         if (cpPatches.containsKey(cpPlaceholder)) {
   204             throw new InternalError("observed CP placeholder twice: " + cpPlaceholder);
   209             throw new InternalError("observed CP placeholder twice: " + cpPlaceholder);
   205         }
   210         }
   206         // insert placeholder in CP and remember the patch
   211         // insert placeholder in CP and remember the patch
   207         int index = cw.newConst((Object) cpPlaceholder);  // TODO check if aready in the constant pool
   212         int index = cw.newConst((Object) cpPlaceholder);  // TODO check if aready in the constant pool
   208         cpPatches.put(cpPlaceholder, new CpPatch(index, arg));
   213         cpPatches.put(cpPlaceholder, new CpPatch(index, cpPlaceholder, arg));
   209         return cpPlaceholder;
   214         return cpPlaceholder;
   210     }
   215     }
   211 
   216 
   212     Object[] cpPatches(byte[] classFile) {
   217     Object[] cpPatches(byte[] classFile) {
   213         int size = getConstantPoolSize(classFile);
   218         int size = getConstantPoolSize(classFile);
   214         Object[] res = new Object[size];
   219         Object[] res = new Object[size];
   215         for (CpPatch p : cpPatches.values()) {
   220         for (CpPatch p : cpPatches.values()) {
   216                 res[p.index] = p.value;
   221             if (p.index >= size)
       
   222                 throw new InternalError("in cpool["+size+"]: "+p+"\n"+Arrays.toString(Arrays.copyOf(classFile, 20)));
       
   223             res[p.index] = p.value;
   217         }
   224         }
   218         return res;
   225         return res;
   219     }
   226     }
   220 
   227 
   221     /**
   228     /**