8230302: GenerateJLIClassesPlugin can generate invalid DirectMethodHandle methods

Reviewed-by: mchung
This commit is contained in:
Claes Redestad 2019-08-29 15:59:00 +02:00
parent e2287af876
commit b4c63048bb
3 changed files with 69 additions and 19 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,9 +31,11 @@ import sun.invoke.util.Wrapper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import static java.lang.invoke.MethodTypeForm.LF_INVINTERFACE;
import static java.lang.invoke.MethodTypeForm.LF_INVVIRTUAL;
/**
* Helper class to assist the GenerateJLIClassesPlugin to get access to
* generate classes ahead of time.
@ -71,8 +73,19 @@ class GenerateJLIClassesHelper {
ArrayList<LambdaForm> forms = new ArrayList<>();
ArrayList<String> names = new ArrayList<>();
for (int i = 0; i < methodTypes.length; i++) {
LambdaForm form = DirectMethodHandle
.makePreparedLambdaForm(methodTypes[i], types[i]);
// invokeVirtual and invokeInterface must have a leading Object
// parameter, i.e., the receiver
if (types[i] == LF_INVVIRTUAL || types[i] == LF_INVINTERFACE) {
if (methodTypes[i].parameterCount() < 1 ||
methodTypes[i].parameterType(0) != Object.class) {
throw new InternalError("Invalid method type for " +
(types[i] == LF_INVVIRTUAL ? "invokeVirtual" : "invokeInterface") +
" DMH, needs at least two leading reference arguments: " +
methodTypes[i]);
}
}
LambdaForm form = DirectMethodHandle.makePreparedLambdaForm(methodTypes[i], types[i]);
forms.add(form);
names.add(form.kind.defaultLambdaName);
}