8160551: assert(c == Bytecodes::_putfield) failed: must be putfield

Wed, 29 Jun 2016 20:16:05 -0400

author
coleenp
date
Wed, 29 Jun 2016 20:16:05 -0400
changeset 8665
8cc2e2729cce
parent 8664
00cbb581da94
child 8666
d3c2e95157e2

8160551: assert(c == Bytecodes::_putfield) failed: must be putfield
Summary: Illegal bytecodes which are detected later hit this assert first.
Reviewed-by: jrose

src/share/vm/interpreter/rewriter.cpp file | annotate | diff | comparison | revisions
test/runtime/Final/Bad.jasm file | annotate | diff | comparison | revisions
test/runtime/Final/PutfieldError.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/interpreter/rewriter.cpp	Mon Dec 12 12:53:38 2016 +0100
     1.2 +++ b/src/share/vm/interpreter/rewriter.cpp	Wed Jun 29 20:16:05 2016 -0400
     1.3 @@ -409,21 +409,20 @@
     1.4              InstanceKlass* klass = method->method_holder();
     1.5              u2 bc_index = Bytes::get_Java_u2(bcp + prefix_length + 1);
     1.6              constantPoolHandle cp(method->constants());
     1.7 -            Symbol* field_name = cp->name_ref_at(bc_index);
     1.8 -            Symbol* field_sig = cp->signature_ref_at(bc_index);
     1.9              Symbol* ref_class_name = cp->klass_name_at(cp->klass_ref_index_at(bc_index));
    1.10  
    1.11              if (klass->name() == ref_class_name) {
    1.12 +              Symbol* field_name = cp->name_ref_at(bc_index);
    1.13 +              Symbol* field_sig = cp->signature_ref_at(bc_index);
    1.14 +
    1.15                fieldDescriptor fd;
    1.16                klass->find_field(field_name, field_sig, &fd);
    1.17                if (fd.access_flags().is_final()) {
    1.18                  if (fd.access_flags().is_static()) {
    1.19 -                  assert(c == Bytecodes::_putstatic, "must be putstatic");
    1.20                    if (!method->is_static_initializer()) {
    1.21                      fd.set_has_initialized_final_update(true);
    1.22                    }
    1.23                  } else {
    1.24 -                  assert(c == Bytecodes::_putfield, "must be putfield");
    1.25                    if (!method->is_object_initializer()) {
    1.26                      fd.set_has_initialized_final_update(true);
    1.27                    }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/Final/Bad.jasm	Wed Jun 29 20:16:05 2016 -0400
     2.3 @@ -0,0 +1,55 @@
     2.4 +/*
     2.5 + * Copyright (c) 2016, 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 +/* Recoded in jasm to provoke an ICCE assigning a non-static final field with putstatic.
    2.28 +class Bad {
    2.29 +  public static final int i; //rewritten
    2.30 +  //rewritten to: public final int i;
    2.31 +  static { i = 5; } // putstatic instruction
    2.32 +}
    2.33 +*/
    2.34 +
    2.35 +super class Bad
    2.36 +	version 53:0
    2.37 +{
    2.38 +
    2.39 +// Remove 'static' keyword
    2.40 +public final Field i:I;
    2.41 +
    2.42 +Method "<init>":"()V"
    2.43 +	stack 1 locals 1
    2.44 +{
    2.45 +		aload_0;
    2.46 +		invokespecial	Method java/lang/Object."<init>":"()V";
    2.47 +		return;
    2.48 +}
    2.49 +
    2.50 +static Method "<clinit>":"()V"
    2.51 +	stack 1 locals 0
    2.52 +{
    2.53 +		iconst_5;
    2.54 +		putstatic	Field i:"I";
    2.55 +		return;
    2.56 +}
    2.57 +
    2.58 +} // end Class Bad
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/Final/PutfieldError.java	Wed Jun 29 20:16:05 2016 -0400
     3.3 @@ -0,0 +1,42 @@
     3.4 +/*
     3.5 + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test PutfieldError
    3.29 + * @bug 8160551
    3.30 + * @summary Throw ICCE rather than crashing for nonstatic final field in static initializer
    3.31 + * @compile Bad.jasm
    3.32 + * @run main PutfieldError
    3.33 + */
    3.34 +
    3.35 +public class PutfieldError {
    3.36 +  public static void main(java.lang.String[] unused) {
    3.37 +    try {
    3.38 +      Bad b = new Bad();
    3.39 +      System.out.println("Bad.i = " + 5);
    3.40 +      throw new RuntimeException("ICCE NOT thrown as expected");
    3.41 +    } catch (IncompatibleClassChangeError icce) {
    3.42 +      System.out.println("ICCE thrown as expected");
    3.43 +    }
    3.44 +  }
    3.45 +}

mercurial