< prev index next >

test/jdk/java/lang/String/concat/WithSecurityManager.java

Print this page
rev 54607 : 8222895: StackOverflowError in custom security manager that relies on ClassSpecializer
Reviewed-by: TBD


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.security.Permission;
  25 
  26 /**
  27  * @test
  28  * @summary String concatenation fails with a custom SecurityManager that uses concatenation
  29  * @bug 8155090 8158851
  30  * @requires !vm.graal.enabled
  31  *
  32  * @compile WithSecurityManager.java
  33  *
  34  * @run main/othervm -Xverify:all WithSecurityManager
  35  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  36  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  37  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  38  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  39  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  40  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  41  *
  42  * @run main/othervm -Xverify:all --limit-modules=java.base WithSecurityManager
  43  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  44  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  45  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  46  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  47  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  48  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  49 */
  50 public class WithSecurityManager {
  51     public static void main(String[] args) throws Throwable {
  52         // First time should succeed to bootstrap everything
  53         {
  54             SecurityManager sm = new SecurityManager() {
  55                 @Override
  56                 public void checkPermission(Permission perm) {
  57                     String abc = "abc";
  58                     String full = abc + "def";






  59                 }
  60             };
  61             System.setSecurityManager(sm);
  62             ClassLoader cl = new ClassLoader() {
  63             };
  64         }
  65 
  66         // Second time should succeed to run after bootstrapping
  67         {
  68             SecurityManager sm = new SecurityManager() {
  69                 @Override
  70                 public void checkPermission(Permission perm) {
  71                     String abc = "abc";
  72                     String full = abc + "def";






  73                 }
  74             };


  75             System.setSecurityManager(sm);
  76             ClassLoader cl = new ClassLoader() {
  77             };
  78         }
  79     }
  80 }


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.security.Permission;
  25 
  26 /**
  27  * @test
  28  * @summary String concatenation fails with a custom SecurityManager that uses concatenation
  29  * @bug 8155090 8158851 8222895
  30  * @requires !vm.graal.enabled
  31  *
  32  * @compile WithSecurityManager.java
  33  *
  34  * @run main/othervm -Xverify:all WithSecurityManager
  35  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  36  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  37  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  38  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  39  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  40  * @run main/othervm -Xverify:all -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  41  *
  42  * @run main/othervm -Xverify:all --limit-modules=java.base WithSecurityManager
  43  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB                  WithSecurityManager
  44  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED            WithSecurityManager
  45  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED            WithSecurityManager
  46  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=BC_SB_SIZED_EXACT      WithSecurityManager
  47  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_SB_SIZED_EXACT      WithSecurityManager
  48  * @run main/othervm -Xverify:all --limit-modules=java.base -Djava.lang.invoke.stringConcat=MH_INLINE_SIZED_EXACT  WithSecurityManager
  49 */
  50 public class WithSecurityManager {
  51     public static void main(String[] args) throws Throwable {
  52         // First time should succeed to bootstrap everything
  53         {
  54             SecurityManager sm = new SecurityManager() {
  55                 @Override
  56                 public void checkPermission(Permission perm) {
  57                     String abc = "abc";
  58                     int ival = perm.hashCode();
  59                     String full = abc + "abc";
  60                     // Contorted to avoid sweeping cases where we've
  61                     // pre-generated commonly used species under the rug
  62                     full = "abc" + ival + "def" + abc + "def" + abc + "def" +
  63                            abc + "def" + ival + "def" + abc + "def" +
  64                            abc + "def" + abc + "def" + abc + "def";
  65                 }
  66             };
  67             System.setSecurityManager(sm);
  68             ClassLoader cl = new ClassLoader() {};

  69         }
  70 
  71         // Second time should succeed to run after bootstrapping
  72         {
  73             SecurityManager sm = new SecurityManager() {
  74                 @Override
  75                 public void checkPermission(Permission perm) {
  76                     String abc = "abc";
  77                     int ival = perm.hashCode();
  78                     String full = abc + "abc";
  79                     // Contorted variant to avoid sweeping cases where we've
  80                     // pre-generated commonly used species under the rug
  81                     full = "abc" + ival + "def" + abc + "def" + abc + "def" +
  82                             abc + "def" + ival + "def" + abc + "def" +
  83                             abc + "def" + abc + "def" + abc + "def";
  84                 }
  85             };
  86 
  87             // Provoke checkPermission invocation
  88             System.setSecurityManager(sm);
  89             ClassLoader cl = new ClassLoader() {};

  90         }
  91     }
  92 }
< prev index next >