मान लीजिए मैं इस कोड है (यह वास्तव में कोई फर्क नहीं पड़ता मुझे लगता है कि, लेकिन सिर्फ यहाँ मामले में यह है):java9 आंतरिक विधि स्पष्ट नहीं
public class AtomicJDK9 {
static AtomicInteger ai = new AtomicInteger(0);
public static void main(String[] args) {
int sum = 0;
for (int i = 0; i < 30_000; ++i) {
sum += atomicIncrement();
}
System.out.println(sum);
}
public static int atomicIncrement() {
ai.getAndAdd(12);
return ai.get();
}
}
और यहाँ मैं इसे कैसे लागू कर रहा हूँ (java9 का उपयोग कर):
java -XX:+UnlockDiagnosticVMOptions
-XX:-TieredCompilation
-XX:+PrintIntrinsics
AtomicJDK9
मैं क्या पता लगाने की कोशिश कर रहा हूं कि आंतरिक कोड द्वारा किन तरीकों को प्रतिस्थापित किया गया है। पहले एक है कि (असुरक्षित अंदर) मारा जाता है:
@HotSpotIntrinsicCandidate
public final int getAndAddInt(Object o, long offset, int delta) {
int v;
do {
v = getIntVolatile(o, offset);
} while (!weakCompareAndSwapIntVolatile(o, offset, v, v + delta));
return v;
}
और इस विधि से ऊपर मंगलाचरण के उत्पादन में वास्तव में मौजूद है:
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
लेकिन, पूरे उत्पादन मुझे उस के लिए (अजीब है है):
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
@ 3 jdk.internal.misc.Unsafe::getIntVolatile (0 bytes) (intrinsic)
@ 18 jdk.internal.misc.Unsafe::weakCompareAndSwapIntVolatile (11 bytes) (intrinsic)
@ 7 jdk.internal.misc.Unsafe::compareAndSwapInt (0 bytes) (intrinsic)
@ 8 jdk.internal.misc.Unsafe::getAndAddInt (27 bytes) (intrinsic)
क्यों getAndAddInt वर्तमान में दो बार उत्पादन में है?
अगर प्राप्त करें और वास्तव में एक आंतरिक कॉल द्वारा प्रतिस्थापित किया गया है, तो कॉल स्टैक एल के नीचे अन्य सभी आंतरिक तरीकों को को बदलने की आवश्यकता क्यों है, अब उनका उपयोग नहीं किया जाएगा। मुझे लगता है कि यह आसान है क्योंकि विधि कॉल के ढेर को नीचे से घुमाया जाता है।
शायद '+ प्रिंटकंपिलेशन '(या जो भी नया एकीकृत एकीकृत समीकरण है) जोड़ रहा है और संदर्भ पर प्रकाश डाला गया है। – the8472