Skip to content

Commit aa23fd9

Browse files
quadhierplummercj
authored andcommitted
8311879: SA ClassWriter generates invalid invokedynamic code
Reviewed-by: matsaave, cjplummer, coleenp
1 parent 6f66213 commit aa23fd9

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/hotspot/share/interpreter/rewriter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) {
288288
// Should do nothing since we are not patching this bytecode
289289
int cache_index = ConstantPool::decode_invokedynamic_index(
290290
Bytes::get_native_u4(p));
291-
// We will reverse the bytecode rewriting _after_ adjusting them.
292-
// Adjust the cache index by offset to the invokedynamic entries in the
293-
// cpCache plus the delta if the invokedynamic bytecodes were adjusted.
294291
int cp_index = _initialized_indy_entries.at(cache_index).constant_pool_index();
295292
assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index");
296293
// zero out 4 bytes

src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -102,7 +102,9 @@ protected short getConstantPoolIndex(int rawcode, int bci) {
102102
// Invokedynamic require special handling
103103
cpCacheIndex = ~cpCacheIndex;
104104
cpCacheIndex = bytes.swapInt(cpCacheIndex);
105-
return (short) cpCache.getEntryAt(cpCacheIndex).getConstantPoolIndex();
105+
short cpIndex = (short) cpCache.getIndyEntryAt(cpCacheIndex).getConstantPoolIndex();
106+
Assert.that(cpool.getTagAt(cpIndex).isInvokeDynamic(), "CP Entry should be InvokeDynamic");
107+
return cpIndex;
106108
} else if (fmt.contains("JJ")) {
107109
// change byte-ordering and go via cache
108110
return (short) cpCache.getEntryAt((int) (0xFFFF & bytes.swapShort((short)cpCacheIndex))).getConstantPoolIndex();

0 commit comments

Comments
 (0)