On Fri, 13 May 2022 12:19:25 GMT, Сергей Цыпанов <d...@openjdk.java.net> wrote:
>> Usually a method declares either no exception, or a couple of them. In the >> first case `List.of()` doesn't allocate, in the second it allocates an >> object with 1-2 fields but without an array, so `List.of()` is likely to be >> more memory-saving > > Usually a method declares either no exception, or a couple of them. In the > first case `List.of()` doesn't allocate, in the second it allocates an object > with 1-2 fields but without an array, so `List.of()` is likely to be more > memory-saving Even in the no exceptions case, the `exceptionTypes` array still has to be allocated/copied by `Method.getExceptionTypes()`[^1] when the `ProxyMethod` constructor[^2] is invoked. So if anything, the `List.of(…)` call should be moved into the `ProxyMethod` constructor. And maybe the call to `Method.getExceptionTypes()` should be changed to `Method.getSharedExceptionTypes()`[^3]. [^1]: https://github.com/openjdk/jdk/blob/e765c42aa71a25a9c30f3409b8fdc6bda6f7b639/src/java.base/share/classes/java/lang/reflect/Method.java#L340-L343 [^2]: https://github.com/openjdk/jdk/blob/e765c42aa71a25a9c30f3409b8fdc6bda6f7b639/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java#L710-L714 [^3]: https://github.com/openjdk/jdk/blob/e765c42aa71a25a9c30f3409b8fdc6bda6f7b639/src/java.base/share/classes/java/lang/reflect/Method.java#L305-L308 ------------- PR: https://git.openjdk.java.net/jdk/pull/7729