8073154: NULL-pointer dereferencing in LIR_OpProfileType::print_instr

Fri, 27 Feb 2015 11:41:42 +0300

author
fzhinkin
date
Fri, 27 Feb 2015 11:41:42 +0300
changeset 9775
9b865b281711
parent 9774
4a7da2a46cb1
child 9776
ce42ae95d4d6

8073154: NULL-pointer dereferencing in LIR_OpProfileType::print_instr
Reviewed-by: iveresov

src/share/vm/c1/c1_LIR.cpp file | annotate | diff | comparison | revisions
test/compiler/print/TestProfileReturnTypePrinting.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/c1/c1_LIR.cpp	Thu Aug 20 11:18:51 2015 -0400
     1.2 +++ b/src/share/vm/c1/c1_LIR.cpp	Fri Feb 27 11:41:42 2015 +0300
     1.3 @@ -2112,8 +2112,14 @@
     1.4  
     1.5  // LIR_OpProfileType
     1.6  void LIR_OpProfileType::print_instr(outputStream* out) const {
     1.7 -  out->print("exact = "); exact_klass()->print_name_on(out);
     1.8 -  out->print("current = "); ciTypeEntries::print_ciklass(out, current_klass());
     1.9 +  out->print("exact = ");
    1.10 +  if  (exact_klass() == NULL) {
    1.11 +    out->print("unknown");
    1.12 +  } else {
    1.13 +    exact_klass()->print_name_on(out);
    1.14 +  }
    1.15 +  out->print(" current = "); ciTypeEntries::print_ciklass(out, current_klass());
    1.16 +  out->print(" ");
    1.17    mdp()->print(out);          out->print(" ");
    1.18    obj()->print(out);          out->print(" ");
    1.19    tmp()->print(out);          out->print(" ");
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/print/TestProfileReturnTypePrinting.java	Fri Feb 27 11:41:42 2015 +0300
     2.3 @@ -0,0 +1,68 @@
     2.4 +/*
     2.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test
    2.29 + * @bug 8073154
    2.30 + * @build TestProfileReturnTypePrinting
    2.31 + * @run main/othervm -XX:TypeProfileLevel=020
    2.32 + *                   -XX:CompileOnly=TestProfileReturnTypePrinting.testMethod
    2.33 + *                   -XX:+IgnoreUnrecognizedVMOptions -XX:+PrintLIR
    2.34 + *                   TestProfileReturnTypePrinting
    2.35 + * @summary Verify that c1's LIR that contains ProfileType node could be dumped
    2.36 + *          without a crash disregard to an exact class knowledge.
    2.37 + */
    2.38 +public class TestProfileReturnTypePrinting {
    2.39 +    private static final int ITERATIONS = 1_000_000;
    2.40 +
    2.41 +    public static void main(String args[]) {
    2.42 +        for (int i = 0; i < ITERATIONS; i++) {
    2.43 +            TestProfileReturnTypePrinting.testMethod(i);
    2.44 +        }
    2.45 +    }
    2.46 +
    2.47 +    private static int testMethod(int i) {
    2.48 +        return TestProfileReturnTypePrinting.foo().hashCode()
    2.49 +                + TestProfileReturnTypePrinting.bar(i).hashCode();
    2.50 +    }
    2.51 +
    2.52 +    /* Exact class of returned value is known statically. */
    2.53 +    private static B foo() {
    2.54 +        return new B();
    2.55 +    }
    2.56 +
    2.57 +    /* Exact class of returned value is not known statically. */
    2.58 +    private static Object bar(int i) {
    2.59 +        if (i % 2 == 0) {
    2.60 +            return new A();
    2.61 +        } else {
    2.62 +            return new B();
    2.63 +        }
    2.64 +    }
    2.65 +
    2.66 +    private static class A {
    2.67 +    }
    2.68 +
    2.69 +    private static class B extends A {
    2.70 +    }
    2.71 +}

mercurial