JDK
Study material
Clone on 19 Aug https://github.com/ymlai87416-oss/jdk https://github.com/ymlai87416-oss/cglib
Class loader
- How to load java class
Compile and JIT
- How JIT is being done?
Data structure
Java lib is java.util.*, and the code path is Link
ArrayList, LinkedLis:
- The class Node
is private, so it never return to outside. Link
- The class Node
HashSet, HashMap, ConcurrentHashMap
- HashSet use HashMap to implement.
- HashMap Internal parameter: load factor=0.75, max cap = 1024^3
- HashMap if key list longer than 8, convert it to tree (Link)[https://github.com/openjdk/jdk/blob/4b03e135e157cb6cc9ba5eebf4a1f1b6e9143f48/src/java.base/share/classes/java/util/HashMap.java#L761]
- before 1.7, it is front insert O(1), now it is back insert O(8), or O(log n)
- ConcurrentHashMap use CAS to keep track of cell version and sychronized the rest.
TreeMap
Stack
- A simple heap implements sift-up and sift-down
Queue and ArrayDeque
- ArrayDeque is just a circular array
Concurrent
Thread: Link
- locate at java.lang
- Thread share the same classloader
CAS:
- locate at java.util.concurrent.atomic
- There is a variable U of Unsafe. A lot of native method there include compareAndSetInt()
- Seems take times when there is a lot of state.
- Implement spinning lock by CAS thread id to internal variable.
Reentrant lock:
- Source code at java.util.concurrent.locks.ReentrantLock
- Similiar to synchronized(lock)
- have conditions so await = wait() and signal = notify() and signalAll = notifyAll()
- Only 1 thread can enter the lock section
Semaphore
- Source code at java.util.concurrent
- AbstractQueueSynchronizer -> Sync -> FairSync and NonFairSync.
- Leetcode question Dinning philosopher seems not working
Barrier
- Source code at java.util.concurrent
- Use to join a number of thread. Use spinning when wait.
- Can also run some Runnable when it is tripped.
Garbage collector
- The garbage collector is locate at jdk.
- The garbage collector code is locate at Here
- Seems most of them have C1 and C2 folder (C1 for client and C2 for server)
- Need a long read
Code injection
cglib / aspectJ / byteBuddy