|
8 | 8 | import java.util.Map;
|
9 | 9 | import java.util.concurrent.atomic.AtomicLong;
|
10 | 10 |
|
11 |
| -import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.*; |
| 11 | +import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.MAX_DIRECT_NODES_COUNT; |
| 12 | +import static org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences.MAX_DIRECT_VARIABLE_NODE_COUNT; |
12 | 13 |
|
13 | 14 | public class LimitContainer {
|
14 | 15 |
|
15 | 16 | private final int maxDirectNodeCount;//-1 - don't check
|
16 | 17 | @NotNull
|
17 | 18 | private final AtomicLong directNodeCount = new AtomicLong();
|
18 |
| - @NotNull |
19 |
| - private final String maxDirectNodeCountMessage; |
20 | 19 |
|
21 | 20 | private final int ssaConstructorSparseExRecordCount;//-1 - don't check
|
22 |
| - @NotNull |
23 |
| - private final String ssaConstructorSparseExRecordCountMessage; |
24 | 21 |
|
25 | 22 | public LimitContainer(@NotNull Map<String, Object> properties) {
|
26 | 23 | maxDirectNodeCount = (int)properties.getOrDefault(MAX_DIRECT_NODES_COUNT, -1);
|
27 |
| - maxDirectNodeCountMessage = (String)properties.getOrDefault(MAX_DIRECT_NODES_COUNT_MESSAGE, "Limits are exceeded"); |
28 | 24 | ssaConstructorSparseExRecordCount = (int)properties.getOrDefault(MAX_DIRECT_VARIABLE_NODE_COUNT, -1);
|
29 |
| - ssaConstructorSparseExRecordCountMessage = (String)properties.getOrDefault(MAX_DIRECT_VARIABLE_NODES_COUNT_MESSAGE, "Limits are exceeded"); |
30 | 25 | }
|
31 | 26 |
|
32 | 27 | public void incrementAndCheckDirectNodeCount(@NotNull ControlFlowGraph graph) {
|
33 | 28 | long newValue = directNodeCount.addAndGet(graph.getBlocks().size());
|
34 | 29 | if (maxDirectNodeCount != -1 && newValue >= maxDirectNodeCount) {
|
35 |
| - throw new LimitExceededDecompilerException(maxDirectNodeCountMessage); |
| 30 | + throw new LimitExceededDecompilerException(maxDirectNodeCount, newValue, "direct nodes"); |
36 | 31 | }
|
37 | 32 | }
|
38 | 33 |
|
39 | 34 | public void checkSFormsFastMapDirect(@NotNull Map<String, SFormsFastMapDirect> inVarVersions,
|
40 | 35 | @NotNull Map<String, SFormsFastMapDirect> outVarVersions) {
|
| 36 | + int newValue = inVarVersions.size() + outVarVersions.size(); |
41 | 37 | if (ssaConstructorSparseExRecordCount != -1 &&
|
42 |
| - inVarVersions.size() + outVarVersions.size() > ssaConstructorSparseExRecordCount) { |
43 |
| - throw new LimitExceededDecompilerException(ssaConstructorSparseExRecordCountMessage); |
| 38 | + newValue > ssaConstructorSparseExRecordCount) { |
| 39 | + throw new LimitExceededDecompilerException(ssaConstructorSparseExRecordCount, newValue, "variable nodes"); |
44 | 40 | }
|
45 | 41 | }
|
46 | 42 |
|
47 | 43 | public static class LimitExceededDecompilerException extends RuntimeException {
|
48 |
| - public LimitExceededDecompilerException(String message) { |
49 |
| - super(message); |
| 44 | + public LimitExceededDecompilerException(long limit, long actualValue, String type) { |
| 45 | + super("Limits for %s are exceeded. Current value: %s, limit: %s".formatted(type, actualValue, limit)); |
50 | 46 | }
|
51 | 47 | }
|
52 | 48 | }
|
0 commit comments