< prev index next >

test/hotspot/jtreg/gc/shenandoah/oom/TestClassLoaderLeak.java

Print this page

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.

  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 /**
 26  * @test
 27  * @summary Test OOME in due to classloader leak
 28  * @requires vm.gc.Shenandoah
 29  * @library /test/lib
 30  * @run driver TestClassLoaderLeak
 31  */
 32 
 33 import java.util.*;
 34 import java.io.*;
 35 import java.nio.*;
 36 import java.nio.file.*;
 37 
 38 import jdk.test.lib.process.OutputAnalyzer;
 39 import jdk.test.lib.process.ProcessTools;
 40 
 41 public class TestClassLoaderLeak {
 42 
 43     static final int SIZE = 1 * 1024 * 1024;
 44     static final int COUNT = 128;
 45 
 46     static volatile Object sink;
 47 
 48     static class Dummy {
 49         static final int[] PAYLOAD = new int[SIZE];
 50     }

106             analyzer.shouldNotContain("java.lang.OutOfMemoryError");
107             analyzer.shouldContain("All good");
108         } else {
109             analyzer.shouldHaveExitValue(1);
110             analyzer.shouldContain("java.lang.OutOfMemoryError");
111             analyzer.shouldNotContain("All good");
112         }
113     }
114 
115     public static void main(String[] args) throws Exception {
116         if (args.length > 0) {
117             String classDir = TestClassLoaderLeak.class.getProtectionDomain().getCodeSource().getLocation().getPath();
118             for (int c = 0; c < COUNT; c++) {
119                 load(classDir);
120             }
121             System.out.println("All good");
122             return;
123         }
124 
125         String[][][] modeHeuristics = new String[][][] {
126              {{"satb"},    {"adaptive", "compact", "static", "aggressive"}},
127              {{"iu"},      {"adaptive", "aggressive"}},
128              {{"passive"}, {"passive"}}

129         };
130 
131         for (String[][] mh : modeHeuristics) {
132             String mode = mh[0][0];
133             String[] heuristics = mh[1];
134             for (String h : heuristics) {
135                 // Forceful enabling should work
136                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading");
137                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloadingWithConcurrentMark");
138 
139                 // Even when concurrent unloading is disabled, Full GC has to recover
140                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading", "-XX:-ClassUnloadingWithConcurrentMark");
141 
142                 // Should OOME when unloading forcefully disabled, even if local flags try to enable it back
143                 failWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading");
144                 failWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading", "-XX:+ClassUnloadingWithConcurrentMark");
145             }
146         }
147     }
148 }

  1 /*
  2  * Copyright (c) 2018, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 /**
 27  * @test
 28  * @summary Test OOME in due to classloader leak
 29  * @requires vm.gc.Shenandoah
 30  * @library /test/lib
 31  * @run driver/timeout=600 TestClassLoaderLeak
 32  */
 33 
 34 import java.util.*;
 35 import java.io.*;
 36 import java.nio.*;
 37 import java.nio.file.*;
 38 
 39 import jdk.test.lib.process.OutputAnalyzer;
 40 import jdk.test.lib.process.ProcessTools;
 41 
 42 public class TestClassLoaderLeak {
 43 
 44     static final int SIZE = 1 * 1024 * 1024;
 45     static final int COUNT = 128;
 46 
 47     static volatile Object sink;
 48 
 49     static class Dummy {
 50         static final int[] PAYLOAD = new int[SIZE];
 51     }

107             analyzer.shouldNotContain("java.lang.OutOfMemoryError");
108             analyzer.shouldContain("All good");
109         } else {
110             analyzer.shouldHaveExitValue(1);
111             analyzer.shouldContain("java.lang.OutOfMemoryError");
112             analyzer.shouldNotContain("All good");
113         }
114     }
115 
116     public static void main(String[] args) throws Exception {
117         if (args.length > 0) {
118             String classDir = TestClassLoaderLeak.class.getProtectionDomain().getCodeSource().getLocation().getPath();
119             for (int c = 0; c < COUNT; c++) {
120                 load(classDir);
121             }
122             System.out.println("All good");
123             return;
124         }
125 
126         String[][][] modeHeuristics = new String[][][] {
127              {{"satb"},         {"adaptive", "compact", "static", "aggressive"}},
128              {{"iu"},           {"adaptive", "aggressive"}},
129              {{"passive"},      {"passive"}},
130              {{"generational"}, {"adaptive"}}
131         };
132 
133         for (String[][] mh : modeHeuristics) {
134             String mode = mh[0][0];
135             String[] heuristics = mh[1];
136             for (String h : heuristics) {
137                 // Forceful enabling should work
138                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading");
139                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloadingWithConcurrentMark");
140 
141                 // Even when concurrent unloading is disabled, Full GC has to recover
142                 passWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:+ClassUnloading", "-XX:-ClassUnloadingWithConcurrentMark");
143 
144                 // Should OOME when unloading forcefully disabled, even if local flags try to enable it back
145                 failWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading");
146                 failWith("-XX:ShenandoahGCMode=" + mode, "-XX:ShenandoahGCHeuristics=" + h, "-XX:-ClassUnloading", "-XX:+ClassUnloadingWithConcurrentMark");
147             }
148         }
149     }
150 }
< prev index next >