@@ -24,6 +24,9 @@ this software and associated documentation files (the "Software"), to deal in
2424
2525package su .interference .core ;
2626
27+ import org .slf4j .Logger ;
28+ import org .slf4j .LoggerFactory ;
29+
2730import java .util .concurrent .atomic .AtomicLong ;
2831import java .util .concurrent .locks .ReentrantLock ;
2932import java .util .concurrent .ConcurrentHashMap ;
@@ -41,32 +44,55 @@ public class LLT {
4144 private static final ReentrantLock rlck = new ReentrantLock ();
4245 private static final ConcurrentHashMap <Long , LLT > pool = new ConcurrentHashMap <Long , LLT >();
4346 private static final ConcurrentHashMap <Long , Frame > frames = new ConcurrentHashMap <Long , Frame >();
47+ private final static Logger logger = LoggerFactory .getLogger (LLT .class );
4448 private final boolean lock ;
4549 private final long id ;
50+ private final StackTraceElement [] trace ;
51+
52+ // WARNING!!!
53+ // change of 'debug' value to true causes decrease total performance
54+ // dev & QA engineers may change this constant
55+ private static final boolean debug = false ;
4656
47- private LLT (boolean lock ) {
48- id = cntr . incrementAndGet () ;
57+ private LLT (long id , boolean lock ) {
58+ this . id = id ;
4959 this .lock = lock ;
60+ this .trace = debug ? Thread .currentThread ().getStackTrace () : null ;
5061 }
5162
5263 public static long getSyncId () {
5364 return sync .get ();
5465 }
5566
5667 public static LLT getLLT () throws InterruptedException {
68+ final long id_ = Thread .currentThread ().getId ();
69+ if (pool .get (id_ ) != null ) {
70+ if (debug ) {
71+ for (StackTraceElement e : pool .get (id_ ).getTrace ()) {
72+ logger .info (e .toString ());
73+ }
74+ }
75+ logger .error ("an unexpected attempt to get llt with id = " +id_ +" which already exists" );
76+ throw new RuntimeException ("an unexpected attempt to get llt with id = " +id_ +" which already exists" );
77+ }
5778 rlck .lock ();
58- final LLT llt = new LLT (false );
79+ final LLT llt = new LLT (id_ , false );
5980 pool .put (llt .getId (), llt );
6081 rlck .unlock ();
6182 return llt ;
6283 }
6384
6485 public static LLT getLLTAndLock () throws InterruptedException {
86+ final long id_ = Thread .currentThread ().getId ();
87+ if (pool .get (id_ ) != null ) {
88+ logger .error ("an unexpected attempt to get llt with id = " +id_ +" which already exists" );
89+ throw new RuntimeException ("an unexpected attempt to get llt with id = " +id_ +" which already exists" );
90+ }
6591 if (Config .getConfig ().SYNC_LOCK_ENABLE ) {
6692 rlck .lock ();
6793 }
6894 while (poolNotEmpty ()) { }
69- final LLT llt = new LLT (true );
95+ final LLT llt = new LLT (id_ , true );
7096 sync .compareAndSet (0 , llt .getId ());
7197 pool .put (llt .getId (), llt );
7298 return llt ;
@@ -103,4 +129,7 @@ public long getId() {
103129 return id ;
104130 }
105131
132+ public StackTraceElement [] getTrace () {
133+ return trace ;
134+ }
106135}
0 commit comments