1
1
/*
2
- * Copyright (c) 2020, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2020, 2025 , 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
* The Universal Permissive License (UPL), Version 1.0
52
52
* Limits on various aspects of a module.
53
53
*/
54
54
public final class ModuleLimits {
55
+
56
+ private static final int SINGLE_MEMORY_COUNT_LIMIT = 1 ;
57
+ private static final int SINGLE_RESULT_COUNT_LIMIT = 1 ;
58
+
55
59
private final int moduleSizeLimit ;
56
60
private final int typeCountLimit ;
57
61
private final int functionCountLimit ;
58
62
private final int tableCountLimit ;
59
- private final int memoryCountLimit ;
60
63
private final int multiMemoryCountLimit ;
61
64
private final int importCountLimit ;
62
65
private final int exportCountLimit ;
@@ -65,32 +68,29 @@ public final class ModuleLimits {
65
68
private final int elementSegmentCountLimit ;
66
69
private final int functionSizeLimit ;
67
70
private final int paramCountLimit ;
68
- private final int resultCountLimit ;
69
71
private final int multiValueResultCountLimit ;
70
72
private final int localCountLimit ;
71
73
private final int tableInstanceSizeLimit ;
72
74
private final int memoryInstanceSizeLimit ;
73
75
private final long memory64InstanceSizeLimit ;
74
76
75
- public ModuleLimits (int moduleSizeLimit , int typeCountLimit , int functionCountLimit , int tableCountLimit , int memoryCountLimit , int multiMemoryCountLimit , int importCountLimit ,
77
+ public ModuleLimits (int moduleSizeLimit , int typeCountLimit , int functionCountLimit , int tableCountLimit , int memoryCountLimit , int importCountLimit ,
76
78
int exportCountLimit , int globalCountLimit ,
77
- int dataSegmentCountLimit , int elementSegmentCountLimit , int functionSizeLimit , int paramCountLimit , int resultCountLimit , int multiValueResultCountLimit , int localCountLimit ,
79
+ int dataSegmentCountLimit , int elementSegmentCountLimit , int functionSizeLimit , int paramCountLimit , int resultCountLimit , int localCountLimit ,
78
80
int tableInstanceSizeLimit , int memoryInstanceSizeLimit , long memory64InstanceSizeLimit ) {
79
81
this .moduleSizeLimit = minUnsigned (moduleSizeLimit , Integer .MAX_VALUE );
80
82
this .typeCountLimit = minUnsigned (typeCountLimit , Integer .MAX_VALUE );
81
83
this .functionCountLimit = minUnsigned (functionCountLimit , Integer .MAX_VALUE );
82
84
this .tableCountLimit = minUnsigned (tableCountLimit , Integer .MAX_VALUE );
83
- this .memoryCountLimit = minUnsigned (memoryCountLimit , Integer .MAX_VALUE );
84
- this .multiMemoryCountLimit = minUnsigned (multiMemoryCountLimit , Integer .MAX_VALUE );
85
+ this .multiMemoryCountLimit = minUnsigned (memoryCountLimit , Integer .MAX_VALUE );
85
86
this .importCountLimit = minUnsigned (importCountLimit , Integer .MAX_VALUE );
86
87
this .exportCountLimit = minUnsigned (exportCountLimit , Integer .MAX_VALUE );
87
88
this .globalCountLimit = minUnsigned (globalCountLimit , Integer .MAX_VALUE );
88
89
this .dataSegmentCountLimit = minUnsigned (dataSegmentCountLimit , Integer .MAX_VALUE );
89
90
this .elementSegmentCountLimit = minUnsigned (elementSegmentCountLimit , Integer .MAX_VALUE );
90
91
this .functionSizeLimit = minUnsigned (functionSizeLimit , Integer .MAX_VALUE );
91
92
this .paramCountLimit = minUnsigned (paramCountLimit , Integer .MAX_VALUE );
92
- this .resultCountLimit = minUnsigned (resultCountLimit , Integer .MAX_VALUE );
93
- this .multiValueResultCountLimit = minUnsigned (multiValueResultCountLimit , Integer .MAX_VALUE );
93
+ this .multiValueResultCountLimit = minUnsigned (resultCountLimit , Integer .MAX_VALUE );
94
94
this .localCountLimit = minUnsigned (localCountLimit , Integer .MAX_VALUE );
95
95
this .tableInstanceSizeLimit = minUnsigned (tableInstanceSizeLimit , MAX_TABLE_INSTANCE_SIZE );
96
96
this .memoryInstanceSizeLimit = minUnsigned (memoryInstanceSizeLimit , MAX_MEMORY_INSTANCE_SIZE );
@@ -120,8 +120,6 @@ private static long minUnsigned(long a, long b) {
120
120
Integer .MAX_VALUE ,
121
121
Integer .MAX_VALUE ,
122
122
Integer .MAX_VALUE ,
123
- Integer .MAX_VALUE ,
124
- Integer .MAX_VALUE ,
125
123
MAX_TABLE_INSTANCE_SIZE ,
126
124
MAX_MEMORY_INSTANCE_SIZE ,
127
125
MAX_MEMORY_64_INSTANCE_SIZE );
@@ -143,11 +141,10 @@ public void checkTableCount(int count) {
143
141
}
144
142
145
143
public void checkMemoryCount (int count , boolean multiMemory ) {
146
- if (multiMemory ) {
147
- assertUnsignedIntLessOrEqual (count , multiMemoryCountLimit , Failure .MEMORY_COUNT_LIMIT_EXCEEDED );
148
- } else {
149
- assertUnsignedIntLessOrEqual (count , memoryCountLimit , Failure .MEMORY_COUNT_LIMIT_EXCEEDED );
144
+ if (!multiMemory ) {
145
+ assertUnsignedIntLessOrEqual (count , SINGLE_MEMORY_COUNT_LIMIT , Failure .MULTIPLE_MEMORIES );
150
146
}
147
+ assertUnsignedIntLessOrEqual (count , multiMemoryCountLimit , Failure .MEMORY_COUNT_LIMIT_EXCEEDED );
151
148
}
152
149
153
150
public void checkImportCount (int count ) {
@@ -179,11 +176,10 @@ public void checkParamCount(int count) {
179
176
}
180
177
181
178
public void checkResultCount (int count , boolean multiValue ) {
182
- if (multiValue ) {
183
- assertUnsignedIntLessOrEqual (count , multiValueResultCountLimit , Failure .RESULT_COUNT_LIMIT_EXCEEDED );
184
- } else {
185
- assertUnsignedIntLessOrEqual (count , resultCountLimit , Failure .RESULT_COUNT_LIMIT_EXCEEDED );
179
+ if (!multiValue ) {
180
+ assertUnsignedIntLessOrEqual (count , SINGLE_RESULT_COUNT_LIMIT , Failure .INVALID_RESULT_ARITY );
186
181
}
182
+ assertUnsignedIntLessOrEqual (count , multiValueResultCountLimit , Failure .RESULT_COUNT_LIMIT_EXCEEDED );
187
183
}
188
184
189
185
public void checkLocalCount (int count ) {
0 commit comments