jvm

Why java bytecode from a class have come code for new staic inner class appear jvm instruction ACONST_NULL

喜欢而已 提交于 2021-02-19 06:11:25
问题 I try to new a inner staic class, But I find that bytecode appear the jvm instruction ACONST_NULL bwteen NEW , DUP and INVOKE_SPECIAL , But I know about a class new is NEW DUP INVOKE_SPECIAL package com.hoho.api; /** * @author linuxea */ public class Main { private static class InnerMain { // no field } public static void main(String[] args) { InnerMain innerMain = new InnerMain(); } } // class version 52.0 (52) // access flags 0x21 public class com/hoho/api/Main { // compiled from: Main.java

Why java bytecode from a class have come code for new staic inner class appear jvm instruction ACONST_NULL

无人久伴 提交于 2021-02-19 06:07:40
问题 I try to new a inner staic class, But I find that bytecode appear the jvm instruction ACONST_NULL bwteen NEW , DUP and INVOKE_SPECIAL , But I know about a class new is NEW DUP INVOKE_SPECIAL package com.hoho.api; /** * @author linuxea */ public class Main { private static class InnerMain { // no field } public static void main(String[] args) { InnerMain innerMain = new InnerMain(); } } // class version 52.0 (52) // access flags 0x21 public class com/hoho/api/Main { // compiled from: Main.java

What's the meaning of “CGC” and “CGCT” in JDK11 “jstat -gc <PID>”?

若如初见. 提交于 2021-02-19 01:33:13
问题 There are two items called CGC and CGCT. I cannot found the documention and man page describing their meaning. # jstat -gc 139934 S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT 0.0 15360.0 0.0 15360.0 113664.0 9216.0 88064.0 23552.0 82304.0 80084.2 10112.0 9360.4 10 0.157 0 0.000 6 0.018 0.175 # java -version openjdk version "11.0.2" 2019-01-15 LTS OpenJDK Runtime Environment Corretto-11.0.2.9.3 (build 11.0.2+9-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.2.9.3

kotlin reflection get list of fields

久未见 提交于 2021-02-18 09:00:21
问题 is there an equivalent for the java reflection foo.getClass().getFields() in Kotlin? I could only find that I can access a field when I know it's name, but I would like to handle fields in a generic way. 回答1: Did you want fields as-in "backing field" or fields as in "properties" ... Kotlin really only has properties. You can get these for some class using: MyTest::class.memberProperties // or MyTest::class.declaredMemberProperties And from a Java Class<T> , use the kotlin extension property

JAVA内存泄漏——内存泄漏原因和内存泄漏检测工具(zt)

元气小坏坏 提交于 2021-02-17 23:04:06
摘要   虽然Java虚拟机(JVM)及其垃圾收集器(garbage collector,GC)负责管理大多数的内存任务,Java软件程序中还是有可能出现内存泄漏。实际上,这在大型项目中是一个常见的问题。避免内存泄漏的第一步是要弄清楚它是如何发生的。本文介绍了编写Java代码的一些常见的内存泄漏陷阱,以及编写不泄漏代码的一些最佳实践。一旦发生了内存泄漏,要指出造成泄漏的代码是非常困难的。因此本文还介绍了一种新工具,用来诊断泄漏并指出根本原因。该工具的开销非常小,因此可以使用它来寻找处于生产中的系统的内存泄漏。 垃圾收集器的作用   虽然垃圾收集器处理了大多数内存管理问题,从而使编程人员的生活变得更轻松了,但是编程人员还是可能犯错而导致出现内存问题。简单地说,GC循环地跟踪所有来自“根”对象(堆栈对象、静态对象、JNI句柄指向的对象,诸如此类)的引用,并将所有它所能到达的对象标记为活动的。程序只可以操纵这些对象;其他的对象都被删除了。因为GC使程序不可能到达已被删除的对象,这么做就是安全的。   虽然内存管理可以说是自动化的,但是这并不能使编程人员免受思考内存管理问题之苦。例如,分配(以及释放)内存总会有开销,虽然这种开销对编程人员来说是不可见的。创建了太多对象的程序将会比完成同样的功能而创建的对象却比较少的程序更慢一些(在其他条件相同的情况下)。   而且,与本文更为密切相关的是

Why is reference assignment atomic in Java?

拟墨画扇 提交于 2021-02-17 19:13:38
问题 As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn't use atomic pointers internally to model this, since otherwise there would be no need for Atomic References. So my questions are: Is atomic reference assignment in the "specs" of java/Scala and guaranteed to happen or is it just a happy coincidence that it is that way most times ? Is atomic reference assignment implied for any language that compiles to the JVM's bytecode (e.g. clojure, Groovy, JRuby,

Why is reference assignment atomic in Java?

Deadly 提交于 2021-02-17 19:11:30
问题 As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn't use atomic pointers internally to model this, since otherwise there would be no need for Atomic References. So my questions are: Is atomic reference assignment in the "specs" of java/Scala and guaranteed to happen or is it just a happy coincidence that it is that way most times ? Is atomic reference assignment implied for any language that compiles to the JVM's bytecode (e.g. clojure, Groovy, JRuby,

When to choose SerialGC, ParallelGC over CMS, G1 in Java?

偶尔善良 提交于 2021-02-17 08:44:49
问题 In Java 9, G1 GC is the default Garbage collector. As of now, I heard of some people preferring CMS garbage collector over G1GC as it seems to be not stable and has some nasty bugs. What happened with ParallelGC (no buzz these days) ? Is there any use case in which we would like to prefer ParallelGC over CMS/G1 ? Also, is there any case where SerialGC could out perform all these parallel collectors ? 回答1: Serial collector Mainly for single-cpu machine. Algorithm: It use a single thread to

How does the compressed pointer implementation in V8 differ from JVM's compressed Oops?

浪尽此生 提交于 2021-02-17 05:17:20
问题 Background: V8 announced a feature called pointer compression (What's happening in V8? - Benedikt Meurer), which is intended to reduce the memory overhead of pointers for 64-bit processes. Java JVM's had a feature called CompressedOops since 2010 (since 6u23). At a first glance, it looks similar but then I realized it is not quite the same. Question: What are the main differences between the pointer compression techniques (V8 vs JVM)? The V8 implementation seems to be still not finalized, but

in java, why do closured variables need to be declared final?

梦想与她 提交于 2021-02-16 19:37:26
问题 final Object o; List l = new ArrayList(){{ // closure over o, in lexical scope this.add(o); }}; why must o be declared final? why don't other JVM languages with mutable vars have this requirement? 回答1: This is not JVM-deep, it all happens at syntactic-sugar level. The reason is that exporting a non-final var via a closure makes it vulnerable to datarace issues and, since Java was designed to be a "blue-collar" language, such a surprising change in the behavior of an otherwise tame and safe