157 @Override 158 protected ConcurrentMap<NashornCallSiteDescriptor, NashornCallSiteDescriptor> computeValue(final Class<?> type) { 159 return new ConcurrentHashMap<>(); 160 } 161 }; 162 163 private static final AccessControlContext GET_LOOKUP_PERMISSION_CONTEXT = 164 AccessControlContextFactory.createAccessControlContext(CallSiteDescriptor.GET_LOOKUP_PERMISSION_NAME); 165 166 @SuppressWarnings("unchecked") 167 private static final Map<String, Reference<NamedOperation>>[] NAMED_OPERATIONS = 168 Stream.generate(() -> Collections.synchronizedMap(new WeakHashMap<>())) 169 .limit(OPERATIONS.length).toArray(Map[]::new); 170 171 private final int flags; 172 173 /** 174 * Function used by {@link NashornTextifier} to represent call site flags in 175 * human readable form 176 * @param flags call site flags 177 * @return human readable form of this callsite descriptor 178 */ 179 public static String toString(final int flags) { 180 final StringBuilder sb = new StringBuilder(); 181 if ((flags & CALLSITE_SCOPE) != 0) { 182 if ((flags & CALLSITE_FAST_SCOPE) != 0) { 183 sb.append("fastscope "); 184 } else { 185 assert (flags & CALLSITE_FAST_SCOPE) == 0 : "can't be fastscope without scope"; 186 sb.append("scope "); 187 } 188 if ((flags & CALLSITE_DECLARE) != 0) { 189 sb.append("declare "); 190 } 191 } 192 if ((flags & CALLSITE_APPLY_TO_CALL) != 0) { 193 sb.append("apply2call "); 194 } 195 if ((flags & CALLSITE_STRICT) != 0) { 196 sb.append("strict "); 197 } 198 return sb.length() == 0 ? "" : " " + sb.toString().trim(); 199 } 200 201 /** 202 * Given call site flags, returns the operation name encoded in them. 203 * @param flags flags 204 * @return the operation name 205 */ 206 public static String getOperationName(final int flags) { 207 switch(flags & OPERATION_MASK) { 208 case 0: return "GET_PROPERTY"; 209 case 1: return "GET_ELEMENT"; 210 case 2: return "GET_METHOD_PROPERTY"; 211 case 3: return "GET_METHOD_ELEMENT"; 212 case 4: return "SET_PROPERTY"; 213 case 5: return "SET_ELEMENT"; 214 case 6: return "CALL"; 215 case 7: return "NEW"; 216 default: throw new AssertionError(); 217 } 218 } | 157 @Override 158 protected ConcurrentMap<NashornCallSiteDescriptor, NashornCallSiteDescriptor> computeValue(final Class<?> type) { 159 return new ConcurrentHashMap<>(); 160 } 161 }; 162 163 private static final AccessControlContext GET_LOOKUP_PERMISSION_CONTEXT = 164 AccessControlContextFactory.createAccessControlContext(CallSiteDescriptor.GET_LOOKUP_PERMISSION_NAME); 165 166 @SuppressWarnings("unchecked") 167 private static final Map<String, Reference<NamedOperation>>[] NAMED_OPERATIONS = 168 Stream.generate(() -> Collections.synchronizedMap(new WeakHashMap<>())) 169 .limit(OPERATIONS.length).toArray(Map[]::new); 170 171 private final int flags; 172 173 /** 174 * Function used by {@link NashornTextifier} to represent call site flags in 175 * human readable form 176 * @param flags call site flags 177 * @param sb the string builder 178 */ 179 public static void appendFlags(final int flags, final StringBuilder sb) { 180 final int pp = flags >> CALLSITE_PROGRAM_POINT_SHIFT; 181 if (pp != 0) { 182 sb.append(" pp=").append(pp); 183 } 184 if ((flags & CALLSITE_SCOPE) != 0) { 185 if ((flags & CALLSITE_FAST_SCOPE) != 0) { 186 sb.append(" fastscope"); 187 } else { 188 sb.append(" scope"); 189 } 190 if ((flags & CALLSITE_DECLARE) != 0) { 191 sb.append(" declare"); 192 } 193 } else { 194 assert (flags & CALLSITE_FAST_SCOPE) == 0 : "can't be fastscope without scope"; 195 } 196 if ((flags & CALLSITE_APPLY_TO_CALL) != 0) { 197 sb.append(" apply2call"); 198 } 199 if ((flags & CALLSITE_STRICT) != 0) { 200 sb.append(" strict"); 201 } 202 } 203 204 /** 205 * Given call site flags, returns the operation name encoded in them. 206 * @param flags flags 207 * @return the operation name 208 */ 209 public static String getOperationName(final int flags) { 210 switch(flags & OPERATION_MASK) { 211 case 0: return "GET_PROPERTY"; 212 case 1: return "GET_ELEMENT"; 213 case 2: return "GET_METHOD_PROPERTY"; 214 case 3: return "GET_METHOD_ELEMENT"; 215 case 4: return "SET_PROPERTY"; 216 case 5: return "SET_ELEMENT"; 217 case 6: return "CALL"; 218 case 7: return "NEW"; 219 default: throw new AssertionError(); 220 } 221 } |