1 /*
   2  * Copyright (c) 2011, Oracle and/or its affiliates. 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  * @bug 6865265
  28  * @summary JVM crashes with "missing exception handler" error
  29  * @author volker.simonis@sap.com
  30  *
  31  * @run main/othervm -XX:CompileThreshold=100 -Xbatch -Xss512k
  32  *      compiler.runtime.StackOverflowBug
  33  */
  34 
  35 package compiler.runtime;
  36 
  37 public class StackOverflowBug {
  38 
  39     public static int run() {
  40         try {
  41             try {
  42                 return run();
  43             } catch (Throwable e) {
  44                 // Notice that the class 'Throwable' is NOT resolved by the verifier,
  45                 // because the verifier only checks if 'Throwable' is assignable to
  46                 // 'java.lang.Throwable' and this check succeeds immediately if the two
  47                 // types have equal names (see 'VerificationType::is_assignable_from' which
  48                 // is called from 'ClassVerifier::verify_exception_handler_table').
  49                 // This is strange, because if the two classes have different names,
  50                 // 'is_assignable_from()' calls 'is_reference_assignable_from()' which resolves
  51                 // both classes by calling 'SystemDictionary::resolve_or_fail()'. This call
  52                 // also takes into account the current class loader (i.e. the one which was used
  53                 // to load this class) and would place a corresponding
  54                 // "java.lang.Throwable / current-Classloader" entry into the system dictionary.
  55                 // This would in turn allow C2 to see 'java.lang.Throwable' as "loaded"
  56                 // (see 'Parse::catch_inline_exceptions()') when this method is compiled.
  57                 return 42;
  58             }
  59         } finally {
  60         }
  61     }
  62 
  63     public static void main(String argv[]) {
  64         run();
  65     }
  66 }
  67 
  68 /*
  69   public static int run();
  70     Code:
  71        0: invokestatic  #2                  // Method run:()I
  72        3: istore_0
  73        4: iload_0
  74        5: ireturn
  75        6: astore_0
  76        7: bipush        42
  77        9: istore_1
  78       10: iload_1
  79       11: ireturn
  80       12: astore_2
  81       13: aload_2
  82       14: athrow
  83     Exception table:
  84        from    to  target type
  85            0     4     6   Class java/lang/Throwable
  86            0     4    12   any
  87            6    10    12   any
  88           12    13    12   any
  89 
  90  */