Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261585

Restore HandleArea used in Deoptimization::uncommon_trap

XMLWordPrintable

    • b10
    • generic
    • generic

        Add HandleMark in Deoptimization::uncommon_trap before Deoptimization::fetch_unroll_info_helper, avoid reference hold in HandleArea increase object lifetime. This makes object lifetime consistent with/without uncommon trap.

        In following test, WeakReference is expected cleared after GC, but it fails with option "-XX:-Inline -XX:-TieredCompilation -XX:CompileCommand=compileonly,UncommonTrapLeak.foo -XX:CompileThreshold=100 -XX:-BackgroundCompilation". Reference's referent object is still alive after "foo" finish, because with uncommon trap, oops are recorded in HandleArea and HandleArea is not poped after uncommon trap process.

        public class UncommonTrapLeak {
            static WeakReference<Object> ref = null;
            static int val = 0;
            public static void main(String args[]) {
                for (int i = 0; i < 300; i++) {
                    val++;
                    foo(i);
                    System.gc();
                    if (ref.get() != null) {
                        throw new RuntimeException("Failed: referent not collected after trap " + ref.get());
                    }
                    if (i % 100 == 0) {
                        System.out.println(i);
                    }
                }
            }

            static void foo(int i) {
                Object o = new Object();
                ref = new WeakReference<Object>(o);
                if (val == 200) {
                    // trigger Deoptimization::uncommon_trap
                    if (o instanceof UncommonTrapLeak) {
                    }
                }
            }
        }

        When Deoptimization::fetch_unroll_info_helper return, all oops in deoptimized frames are saved in Deoptimization::UnrollBlock or Thread data structure, HandleArea can be restored safely.

        1. local and expression oops raw address is stored in vframeArrayElement _locals/_expressions as intptr
        2. return value restore, raw oop recoreded in frame // (oop *)map->location(rax->as_VMReg());
        3. exception object, raw oop recorded on Thread._exception_oop

        In deoptimize blob, JRT_BLOCK_ENTRY(Deoptimization::fetch_unroll_info) has HandleMarkCleaner, HandleArea is restored after Deoptimization::fetch_unroll_info_helper finish. So it's also safe to add HandleMark in Deoptimization::uncommon_trap before fetch_unroll_info_helper.
        Proposed fix is adding HandleMark in Deoptimization::uncommon_trap before Deoptimization::fetch_unroll_info_helper.

              hshi Hui Shi
              hshi Hui Shi
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: