* Called by the garbage collector on an object when garbage collection * determines that there are no more references to the object. * A subclass overrides the {@code finalize} method to dispose of * system resources or to perform other cleanup.
* The general contract of {@code finalize} is that it is invoked * if and when the Java™ virtual * machine has determined that there is no longer any * means by which this object can be accessed by any thread that has * not yet died, except as a result of an action taken by the * finalization of some other object or class which is ready to be * finalized. The {@code finalize} method may take any action, including * making this object available again to other threads; the usual purpose * of {@code finalize}, however, is to perform cleanup actions before * the object is irrevocably discarded. For example, the finalize method * for an object that represents an input/output connection might perform * explicit I/O transactions to break the connection before the object is * permanently discarded.
* The Java programming language does not guarantee which thread will * invoke the {@code finalize} method for any given object. It is * guaranteed, however, that the thread that invokes finalize will not * be holding any user-visible synchronization locks when finalize is * invoked. If an uncaught exception is thrown by the finalize method, * the exception is ignored and finalization of that object terminates.
* After the {@code finalize} method has been invoked for an object, no * further action is taken until the Java virtual machine has again * determined that there is no longer any means by which this object can * be accessed by any thread that has not yet died, including possible * actions by other objects or classes which are ready to be finalized, * at which point the object may be discarded.
creating 0 objects, current 1 are alive. creating 100000 objects, current 100001 are alive. creating 200000 objects, current 200001 are alive. creating 300000 objects, current 300001 are alive. creating 400000 objects, current 400001 are alive. creating 500000 objects, current 500001 are alive. creating 600000 objects, current 600001 are alive. creating 700000 objects, current 700001 are alive. creating 800000 objects, current 800001 are alive. creating 900000 objects, current 900001 are alive. creating 1000000 objects, current 1000001 are alive. creating 1100000 objects, current 1100001 are alive. creating 1200000 objects, current 1200001 are alive. // ygc 失败,下面直接进行 fgc 了 [GC (Allocation Failure) [PSYoungGen: 76800K->12800K(89600K)] 76800K->71066K(192000K), 0.3839994 secs] [Times: user=1.87 sys=0.07, real=0.38 secs] // 执行 fgc [Full GC (Ergonomics) [PSYoungGen: 12800K->0K(89600K)] [ParOldGen: 58266K->70801K(102400K)] 71066K->70801K(192000K), [Metaspace: 3696K->3696K(1056768K)], 1.3266229 secs] [Times: user=4.89 sys=0.17, real=1.33 secs] creating 1300000 objects, current 1296221 are alive.
[Full GC (Ergonomics) [PSYoungGen: 76800K->76784K(89600K)] [ParOldGen: 102028K->101994K(102400K)] 178828K->178778K(192000K), [Metaspace: 3716K->3716K(1056768K)], 0.4323213 secs] [Times: user=2.13 sys=0.04, real=0.43 secs] [Full GC (Ergonomics) Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded [PSYoungGen: 76799K->76697K(89600K)] [ParOldGen: 101994K->101994K(102400K)] 178793K->178691K(192000K), [Metaspace: 3720K->3720K(1056768K)], 0.3325707 secs] [Times: user=1.70 sys=0.02, real=0.33 secs] Heap PSYoungGen total 89600K, used 76800K [0x00000007b9c00000, 0x00000007c0000000, 0x00000007c0000000) eden space 76800K, 100% used [0x00000007b9c00000,0x00000007be700000,0x00000007be700000) from space 12800K, 0% used [0x00000007be700000,0x00000007be700000,0x00000007bf380000) to space 12800K, 0% used [0x00000007bf380000,0x00000007bf380000,0x00000007c0000000) ParOldGen total 102400K, used 101994K [0x00000007b3800000, 0x00000007b9c00000, 0x00000007b9c00000) object space 102400K, 99% used [0x00000007b3800000,0x00000007b9b9a8e0,0x00000007b9c00000) Metaspace used 3751K, capacity 4670K, committed 4864K, reserved 1056768K class space used 404K, capacity 434K, committed 512K, reserved 1048576K at java.lang.ref.Finalizer.register(Finalizer.java:87) at java.lang.Object.<init>(Object.java:37) at com.glmapper.bridge.boot.finalize.TestMain.<init>(TestMain.java:13) at com.glmapper.bridge.boot.finalize.TestMain.main(TestMain.java:28)
class space used 404K, capacity 434K, committed 512K, reserved 1048576K at java.lang.ref.Finalizer.register(Finalizer.java:87) at java.lang.Object.<init>(Object.java:37) at com.glmapper.bridge.boot.finalize.TestMain.<init>(TestMain.java:13) at com.glmapper.bridge.boot.finalize.TestMain.main(TestMain.java:28)