Skip to content

Commit cedde80

Browse files
committed
Fixed invokedynamic code generation
1 parent 430aaf9 commit cedde80

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

LambdaTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.List;
2+
import java.util.ArrayList;
3+
4+
5+
public class LambdaTest<T> {
6+
7+
public static void main(final String[] args) {
8+
final LambdaTest<String> test = new LambdaTest<String>();
9+
10+
test.doStreamProcessing();
11+
}
12+
13+
public void doStreamProcessing() {
14+
final List<String> list = new ArrayList<String>();
15+
16+
17+
list.add("Apple");
18+
list.add("Pear");
19+
list.add("Pineapple");
20+
list.add("Blueberry");
21+
22+
list.stream().filter(x -> x.toLowerCase().startsWith("A")).forEach(System.out::println);
23+
}
24+
}

src/bytecode/io/reader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl ClassReader {
461461
0x68 => Instruction::IMUL,
462462
0x74 => Instruction::INEG,
463463
0xc1 => Instruction::INSTANCEOF(reader.get_u16()),
464-
0xba => Instruction::INVOKEDYNAMIC(reader.get_u16()),
464+
0xba => (Instruction::INVOKEDYNAMIC(reader.get_u16()), reader.get_u16()).0,
465465
0xb9 => (Instruction::INVOKEINTERFACE(reader.get_u16(), reader.get_u8()), reader.get_u8()).0,
466466
0xb7 => Instruction::INVOKESPECIAL(reader.get_u16()),
467467
0xb8 => Instruction::INVOKESTATIC(reader.get_u16()),

src/bytecode/io/writer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl<'a> ClassWriter<'a> {
5656
&Constant::InterfaceMethodRef { class_index: ref c_idx, name_and_type_index: ref n_idx } => self.write_u8(11).and(self.write_u16(c_idx.idx as u16)).and(self.write_u16(n_idx.idx as u16)),
5757
&Constant::NameAndType { name_index: ref n_idx, descriptor_index: ref d_idx } => self.write_u8(12).and(self.write_u16(n_idx.idx as u16)).and(self.write_u16(d_idx.idx as u16)),
5858
&Constant::MethodHandle { reference_kind: ref kind, reference_index: ref r_idx } => self.write_u8(15).and(self.write_u8(kind.to_u8())).and(self.write_u16(r_idx.idx as u16)),
59+
&Constant::InvokeDynamic { bootstrap_method_attr_index: ref m_idx, name_and_type_index: ref n_idx } => self.write_u8(18).and(self.write_u16(m_idx.idx as u16)).and(self.write_u16(n_idx.idx as u16)),
5960
&Constant::Placeholder => Ok(0),
6061
_ => Err(Error::new(ErrorKind::InvalidData, "Unknown constant detected"))
6162
}
@@ -224,6 +225,8 @@ impl<'a> ClassWriter<'a> {
224225
self.write_u16(cp.get_utf8_index("BootstrapMethods") as u16)
225226
// attribute_length
226227
.and(self.write_u32(table.iter().fold(2, |acc, method| acc + 4 + method.bootstrap_arguments.len() as u32 * 2)))
228+
// num_bootstrap_methods
229+
.and(self.write_u16(table.len() as u16))
227230
// bootstrap_methods
228231
.and(table.iter().fold(Ok(0), |_, method| {
229232
// bootstrap_method_ref

0 commit comments

Comments
 (0)