|
1 | 1 | /* |
2 | | - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | /* |
25 | 25 | * @test |
26 | 26 | * @summary Testing Classfile stack maps generator. |
27 | | - * @bug 8305990 8320222 8320618 |
| 27 | + * @bug 8305990 8320222 8320618 8335475 |
28 | 28 | * @build testdata.* |
29 | 29 | * @run junit StackMapsTest |
30 | 30 | */ |
|
36 | 36 | import java.nio.file.FileSystems; |
37 | 37 | import java.nio.file.Files; |
38 | 38 | import org.junit.jupiter.api.Test; |
| 39 | +import org.junit.jupiter.params.ParameterizedTest; |
| 40 | +import org.junit.jupiter.params.provider.EnumSource; |
| 41 | + |
| 42 | +import static java.lang.constant.ConstantDescs.MTD_void; |
39 | 43 | import static org.junit.jupiter.api.Assertions.*; |
40 | 44 | import static helpers.TestUtil.assertEmpty; |
41 | 45 | import static java.lang.classfile.ClassFile.ACC_STATIC; |
@@ -238,7 +242,7 @@ void testClassVersions() throws Exception { |
238 | 242 | @Test |
239 | 243 | void testInvalidAALOADStack() { |
240 | 244 | ClassFile.of().build(ClassDesc.of("Test"), clb |
241 | | - -> clb.withMethodBody("test", ConstantDescs.MTD_void, 0, cob |
| 245 | + -> clb.withMethodBody("test", MTD_void, 0, cob |
242 | 246 | -> cob.bipush(10) |
243 | 247 | .anewarray(ConstantDescs.CD_Object) |
244 | 248 | .lconst_1() //long on stack caused NPE, see 8320618 |
@@ -312,4 +316,28 @@ void testInvalidStack() throws Exception { |
312 | 316 | cb.pop(); |
313 | 317 | }))); |
314 | 318 | } |
| 319 | + |
| 320 | + @ParameterizedTest |
| 321 | + @EnumSource(ClassFile.StackMapsOption.class) |
| 322 | + void testEmptyCounters(ClassFile.StackMapsOption option) { |
| 323 | + var cf = ClassFile.of(option); |
| 324 | + var bytes = cf.build(ClassDesc.of("Test"), clb -> clb |
| 325 | + .withMethodBody("a", MTD_void, ACC_STATIC, CodeBuilder::return_) |
| 326 | + .withMethodBody("b", MTD_void, 0, CodeBuilder::return_) |
| 327 | + ); |
| 328 | + |
| 329 | + var cm = ClassFile.of().parse(bytes); |
| 330 | + for (var method : cm.methods()) { |
| 331 | + var name = method.methodName(); |
| 332 | + var code = method.code().orElseThrow(); |
| 333 | + if (name.equalsString("a")) { |
| 334 | + assertEquals(0, code.maxLocals()); // static method |
| 335 | + assertEquals(0, code.maxStack()); |
| 336 | + } else { |
| 337 | + assertTrue(name.equalsString("b")); |
| 338 | + assertEquals(1, code.maxLocals()); // instance method |
| 339 | + assertEquals(0, code.maxStack()); |
| 340 | + } |
| 341 | + } |
| 342 | + } |
315 | 343 | } |
0 commit comments