diff --git a/src/share/vm/interpreter/rewriter.cpp b/src/share/vm/interpreter/rewriter.cpp index 208f8617d5d1a38dc1dff58897b0a9824ff36076..2474ae758ba91c4f39d0fd83de6c3d0a90b5f191 100644 --- a/src/share/vm/interpreter/rewriter.cpp +++ b/src/share/vm/interpreter/rewriter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -250,8 +250,8 @@ void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) { // We will reverse the bytecode rewriting _after_ adjusting them. // Adjust the cache index by offset to the invokedynamic entries in the // cpCache plus the delta if the invokedynamic bytecodes were adjusted. - cache_index = cp_cache_delta() + _first_iteration_cp_cache_limit; - int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index); + int adjustment = cp_cache_delta() + _first_iteration_cp_cache_limit; + int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index - adjustment); assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index"); // zero out 4 bytes Bytes::put_Java_u4(p, 0); @@ -453,18 +453,7 @@ methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) { return method; } -void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) { - ResourceMark rm(THREAD); - Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); - // (That's all, folks.) -} - - -Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array* methods, TRAPS) - : _klass(klass), - _pool(cpool), - _methods(methods) -{ +void Rewriter::rewrite_bytecodes(TRAPS) { assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); // determine index maps for Method* rewriting @@ -508,6 +497,29 @@ Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Arrayconstants(), klass->methods(), CHECK); + // (That's all, folks.) +} + + +Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array* methods, TRAPS) + : _klass(klass), + _pool(cpool), + _methods(methods) +{ + + // Rewrite bytecodes - exception here exits. + rewrite_bytecodes(CHECK); + + // Stress restoring bytecodes + if (StressRewriter) { + restore_bytecodes(); + rewrite_bytecodes(CHECK); + } // allocate constant pool cache, now that we've seen all the bytecodes make_constant_pool_cache(THREAD); @@ -523,6 +535,7 @@ Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Arraylength(); for (int i = len-1; i >= 0; i--) { methodHandle m(THREAD, _methods->at(i)); diff --git a/src/share/vm/interpreter/rewriter.hpp b/src/share/vm/interpreter/rewriter.hpp index 2c7990fa7e5417ca3e37f53992016af7984a4a53..aa4b7cd5228193f46ae05febc6d697c16a5d22a3 100644 --- a/src/share/vm/interpreter/rewriter.hpp +++ b/src/share/vm/interpreter/rewriter.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -199,6 +199,9 @@ class Rewriter: public StackObj { void patch_invokedynamic_bytecodes(); + // Do all the work. + void rewrite_bytecodes(TRAPS); + // Revert bytecodes in case of an exception. void restore_bytecodes(); diff --git a/src/share/vm/oops/constantPool.cpp b/src/share/vm/oops/constantPool.cpp index 16b53a69929614b0b95ace12913eabfcf33b622e..3f37810d20dd9c0d5b5269ff989388966c3656ca 100644 --- a/src/share/vm/oops/constantPool.cpp +++ b/src/share/vm/oops/constantPool.cpp @@ -82,6 +82,9 @@ ConstantPool::ConstantPool(Array* tags) { void ConstantPool::deallocate_contents(ClassLoaderData* loader_data) { MetadataFactory::free_metadata(loader_data, cache()); set_cache(NULL); + MetadataFactory::free_array(loader_data, reference_map()); + set_reference_map(NULL); + MetadataFactory::free_array(loader_data, operands()); set_operands(NULL); diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index e7f6340969236e73be13aa4768489a440528ff17..9d9ecacc4c692dfea738be0e9cc78c0133dbeed6 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1258,6 +1258,9 @@ class CommandLineFlags { develop(bool, TraceJNICalls, false, \ "Trace JNI calls") \ \ + develop(bool, StressRewriter, false, \ + "Stress linktime bytecode rewriting") \ + \ notproduct(bool, TraceJVMCalls, false, \ "Trace JVM calls") \ \ diff --git a/src/share/vm/utilities/array.hpp b/src/share/vm/utilities/array.hpp index 9f8e45f3243506dc495a3e8e9f6ef9bd79e6d4fd..0fbcd94d2beff2d1de3f4eaea6d143459151b8f5 100644 --- a/src/share/vm/utilities/array.hpp +++ b/src/share/vm/utilities/array.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,7 +58,7 @@ class ResourceArray: public ResourceObj { void initialize(size_t esize, int length) { assert(length >= 0, "illegal length"); - assert(_data == NULL, "must be new object"); + assert(StressRewriter || _data == NULL, "must be new object"); _length = length; _data = resource_allocate_bytes(esize * length); DEBUG_ONLY(init_nesting();) diff --git a/test/runtime/lambda-features/InvokespecialInterface.java b/test/runtime/lambda-features/InvokespecialInterface.java index 25e7904c2576caa44535464c41b8c267418c7248..80c26186da2c691aa13c28ee66c3c4d4413287b8 100644 --- a/test/runtime/lambda-features/InvokespecialInterface.java +++ b/test/runtime/lambda-features/InvokespecialInterface.java @@ -26,8 +26,9 @@ * @test * @bug 8032024 * @bug 8025937 + * @bug 8033528 * @summary [JDK 8] Test invokespecial and invokeinterface with the same JVM_CONSTANT_InterfaceMethodref - * @run main InvokespecialInterface + * @run main/othervm -XX:+StressRewriter InvokespecialInterface */ import java.util.function.*; import java.util.*;