コード例 #1
0
 void cacheVisitedState(
     APTPreprocHandler.State inputState,
     APTPreprocHandler outputHandler,
     FilePreprocessorConditionState pcState) {
   if (cacheStates && inputState.isCompileContext()) {
     stateCacheLock.writeLock().lock();
     try {
       if ((stateCache.isEmpty() || APTHandlersSupport.getIncludeStackDepth(inputState) == 1)
           && isCacheableState(inputState)) {
         if (stateCache.size() == CACHE_SIZE) {
           int min = Integer.MAX_VALUE;
           APTPreprocHandler.StateKey key = null;
           for (Map.Entry<APTPreprocHandler.StateKey, Value> entry : stateCache.entrySet()) {
             if (entry.getValue().value.get() == null) {
               key = entry.getKey();
               break;
             }
             if (entry.getValue().count < min) {
               key = entry.getKey();
               min = entry.getValue().count;
             }
           }
           stateCache.remove(key);
         }
         stateCache.put(
             createKey(inputState),
             new Value(new PreprocessorStatePair(outputHandler.getState(), pcState)));
       }
     } finally {
       stateCacheLock.writeLock().unlock();
     }
   }
 }
コード例 #2
0
 /*package-local*/ PreprocessorStatePair getCachedVisitedState(
     APTPreprocHandler.State inputState) {
   PreprocessorStatePair res = null;
   if (cacheStates && inputState.isCompileContext()) {
     if (TRACE) {
       stateCacheAttempt++;
     }
     stateCacheLock.readLock().lock();
     APTPreprocHandler.StateKey key = null;
     try {
       if (isCacheableState(inputState)) {
         key = createKey(inputState);
         Value value = stateCache.get(key);
         if (value != null) {
           res = value.value.get();
           value.count++;
         }
       }
     } finally {
       stateCacheLock.readLock().unlock();
     }
     if (TRACE && res != null) {
       stateCacheSuccessAttempt++;
       System.err.println(
           "State Cache Attempt="
               + stateCacheAttempt
               + " successful="
               + stateCacheSuccessAttempt
               + " cache size="
               + stateCache.size()
               + " in file "
               + file.getName());
       System.err.println("    Key=" + key);
       System.err.println("    Res=" + createKey(res.state));
     }
   }
   return res;
 }