Mercurial > hg > graal-jvmci-8
diff src/share/vm/interpreter/rewriter.hpp @ 13056:41cb10cbfb3c
8025937: assert(existing_f1 == NULL || existing_f1 == f1) failed: illegal field change
Summary: Create extra constant pool cache entries for invokespecial/InterfaceMethodref to hold the alternate resolution.
Reviewed-by: jrose, lfoltan, hseigel
author | coleenp |
---|---|
date | Wed, 13 Nov 2013 16:42:24 -0500 |
parents | cc6a617fffd2 |
children | d61a1a166f44 |
line wrap: on
line diff
--- a/src/share/vm/interpreter/rewriter.hpp Wed Nov 13 07:31:26 2013 -0800 +++ b/src/share/vm/interpreter/rewriter.hpp Wed Nov 13 16:42:24 2013 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2013, 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 @@ -46,55 +46,102 @@ intArray _method_handle_invokers; int _resolved_reference_limit; + // For mapping invokedynamic bytecodes, which are discovered during method + // scanning. The invokedynamic entries are added at the end of the cpCache. + // If there are any invokespecial/InterfaceMethodref special case bytecodes, + // these entries are added before invokedynamic entries so that the + // invokespecial bytecode 16 bit index doesn't overflow. + intStack _invokedynamic_cp_cache_map; + + // For patching. + GrowableArray<address>* _patch_invokedynamic_bcps; + GrowableArray<int>* _patch_invokedynamic_refs; + void init_maps(int length) { _cp_map.initialize(length, -1); // Choose an initial value large enough that we don't get frequent // calls to grow(). - _cp_cache_map.initialize(length / 2); + _cp_cache_map.initialize(length/2); // Also cache resolved objects, in another different cache. _reference_map.initialize(length, -1); - _resolved_references_map.initialize(length / 2); - _invokedynamic_references_map.initialize(length / 2); + _resolved_references_map.initialize(length/2); + _invokedynamic_references_map.initialize(length/2); _resolved_reference_limit = -1; - DEBUG_ONLY(_cp_cache_index_limit = -1); + _first_iteration_cp_cache_limit = -1; + + // invokedynamic specific fields + _invokedynamic_cp_cache_map.initialize(length/4); + _patch_invokedynamic_bcps = new GrowableArray<address>(length/4); + _patch_invokedynamic_refs = new GrowableArray<int>(length/4); } - int _cp_cache_index_limit; + int _first_iteration_cp_cache_limit; void record_map_limits() { -#ifdef ASSERT - // Record initial size of the two arrays generated for the CP cache: - _cp_cache_index_limit = _cp_cache_map.length(); -#endif //ASSERT + // Record initial size of the two arrays generated for the CP cache + // relative to walking the constant pool. + _first_iteration_cp_cache_limit = _cp_cache_map.length(); _resolved_reference_limit = _resolved_references_map.length(); } + int cp_cache_delta() { + // How many cp cache entries were added since recording map limits after + // cp cache initialization? + assert(_first_iteration_cp_cache_limit != -1, "only valid after first iteration"); + return _cp_cache_map.length() - _first_iteration_cp_cache_limit; + } + int cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; } bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; } + int add_map_entry(int cp_index, intArray* cp_map, intStack* cp_cache_map) { + assert(cp_map->at(cp_index) == -1, "not twice on same cp_index"); + int cache_index = cp_cache_map->append(cp_index); + cp_map->at_put(cp_index, cache_index); + return cache_index; + } + int add_cp_cache_entry(int cp_index) { assert(_pool->tag_at(cp_index).value() != JVM_CONSTANT_InvokeDynamic, "use indy version"); - assert(_cp_map[cp_index] == -1, "not twice on same cp_index"); - assert(_cp_cache_index_limit == -1, "do not add cache entries after first iteration"); - int cache_index = _cp_cache_map.append(cp_index); - _cp_map.at_put(cp_index, cache_index); + assert(_first_iteration_cp_cache_limit == -1, "do not add cache entries after first iteration"); + int cache_index = add_map_entry(cp_index, &_cp_map, &_cp_cache_map); assert(cp_entry_to_cp_cache(cp_index) == cache_index, ""); assert(cp_cache_entry_pool_index(cache_index) == cp_index, ""); return cache_index; } - // add a new CP cache entry beyond the normal cache (for invokedynamic only) int add_invokedynamic_cp_cache_entry(int cp_index) { assert(_pool->tag_at(cp_index).value() == JVM_CONSTANT_InvokeDynamic, "use non-indy version"); - assert(_cp_map[cp_index] == -1, "do not map from cp_index"); - assert(_cp_cache_index_limit >= 0, "add indy cache entries after first iteration"); + assert(_first_iteration_cp_cache_limit >= 0, "add indy cache entries after first iteration"); + // add to the invokedynamic index map. + int cache_index = _invokedynamic_cp_cache_map.append(cp_index); + // do not update _cp_map, since the mapping is one-to-many + assert(invokedynamic_cp_cache_entry_pool_index(cache_index) == cp_index, ""); + // this index starts at one but in the bytecode it's appended to the end. + return cache_index + _first_iteration_cp_cache_limit; + } + + int invokedynamic_cp_cache_entry_pool_index(int cache_index) { + int cp_index = _invokedynamic_cp_cache_map[cache_index]; + return cp_index; + } + + // add a new CP cache entry beyond the normal cache for the special case of + // invokespecial with InterfaceMethodref as cpool operand. + int add_invokespecial_cp_cache_entry(int cp_index) { + assert(_first_iteration_cp_cache_limit >= 0, "add these special cache entries after first iteration"); + // Don't add InterfaceMethodref if it already exists at the end. + for (int i = _first_iteration_cp_cache_limit; i < _cp_cache_map.length(); i++) { + if (cp_cache_entry_pool_index(i) == cp_index) { + return i; + } + } int cache_index = _cp_cache_map.append(cp_index); - assert(cache_index >= _cp_cache_index_limit, ""); + assert(cache_index >= _first_iteration_cp_cache_limit, ""); // do not update _cp_map, since the mapping is one-to-many assert(cp_cache_entry_pool_index(cache_index) == cp_index, ""); return cache_index; } - // fix duplicated code later int cp_entry_to_resolved_references(int cp_index) const { assert(has_entry_in_resolved_references(cp_index), "oob"); return _reference_map[cp_index]; @@ -105,10 +152,7 @@ // add a new entry to the resolved_references map int add_resolved_references_entry(int cp_index) { - assert(_reference_map[cp_index] == -1, "not twice on same cp_index"); - assert(_resolved_reference_limit == -1, "do not add CP refs after first iteration"); - int ref_index = _resolved_references_map.append(cp_index); - _reference_map.at_put(cp_index, ref_index); + int ref_index = add_map_entry(cp_index, &_reference_map, &_resolved_references_map); assert(cp_entry_to_resolved_references(cp_index) == ref_index, ""); return ref_index; } @@ -137,7 +181,7 @@ // Access the contents of _cp_cache_map to determine CP cache layout. int cp_cache_entry_pool_index(int cache_index) { int cp_index = _cp_cache_map[cache_index]; - return cp_index; + return cp_index; } // All the work goes in here: @@ -145,14 +189,18 @@ void compute_index_maps(); void make_constant_pool_cache(TRAPS); - void scan_method(Method* m, bool reverse = false); + void scan_method(Method* m, bool reverse, TRAPS); void rewrite_Object_init(methodHandle m, TRAPS); - void rewrite_member_reference(address bcp, int offset, bool reverse = false); - void maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse = false); - void rewrite_invokedynamic(address bcp, int offset, bool reverse = false); - void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse = false); + void rewrite_member_reference(address bcp, int offset, bool reverse); + void maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse); + void rewrite_invokedynamic(address bcp, int offset, bool reverse); + void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse); + void rewrite_invokespecial(address bcp, int offset, bool reverse, TRAPS); + + void patch_invokedynamic_bytecodes(); + // Revert bytecodes in case of an exception. - void restore_bytecodes(); + void restore_bytecodes(TRAPS); static methodHandle rewrite_jsrs(methodHandle m, TRAPS); public: