Integrated: 8311879: SA ClassWriter generates invalid invokedynamic code
Daohan Qu
dqu at openjdk.org
Wed Jul 19 19:28:56 UTC 2023
On Wed, 12 Jul 2023 13:49:17 GMT, Daohan Qu <dqu at openjdk.org> wrote:
> This patch should fix the wrong CP index for `invokedynamic` instruction generated by SA's `ClassWriter`. The buggy code in `sun.jvm.hotspot.tools.jcore.ByteCodeRewriter` should have been up-to-date with the following code snippet in `hotspot`:
>
> https://github.com/openjdk/jdk/blob/753bd563ecca6bb5ff9b5ebc0957bc1854dce78d/src/hotspot/share/interpreter/rewriter.cpp#L291-L294
>
> The comments above seem to be obsolete since the following change made in [JDK-8301995](https://bugs.openjdk.org/browse/JDK-8301995). So I also remove them.
>
>
> + // Should do nothing since we are not patching this bytecode
> int cache_index = ConstantPool::decode_invokedynamic_index(
> Bytes::get_native_u4(p));
> // 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.
> - int adjustment = cp_cache_delta() + _first_iteration_cp_cache_limit;
> - int cp_index = invokedynamic_cp_cache_entry_pool_index(cache_index - adjustment);
> + int cp_index = _initialized_indy_entries.at(cache_index).constant_pool_index();
> assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
>
>
> This fix is straightforward and thank @asotona for finding this bug!
>
> ### Test Results of release build on Linux x64
> * `jtreg:test/hotspot/jtreg/serviceability` and `jtreg:test/jdk/sun/tools/`: PASS
> * `tier1`: PASS
> * `tier2` and `tier3`: PASS (Failures of `sun/security/lib/cacerts/VerifyCACerts.java` and `sun/security/pkcs11/KeyStore/CertChainRemoval.java` seem to be unrelated to this patch)
This pull request has now been integrated.
Changeset: aa23fd98
Author: Daohan Qu <dqu at openjdk.org>
Committer: Chris Plummer <cjplummer at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/aa23fd98f528069f5c613f43e335a0585a490176
Stats: 7 lines in 2 files changed: 2 ins; 3 del; 2 mod
8311879: SA ClassWriter generates invalid invokedynamic code
Reviewed-by: matsaave, cjplummer, coleenp
-------------
PR: https://git.openjdk.org/jdk/pull/14852
More information about the serviceability-dev
mailing list