From 684b4f7551f571c6c3a705427ee9f465c69968f6 Mon Sep 17 00:00:00 2001
From: Sergey Bylokhov <serb@openjdk.org>
Date: Fri, 11 May 2018 15:27:51 -0700
Subject: [PATCH] 8202878:
 com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java fails

Reviewed-by: prr
---
 test/jdk/ProblemList.txt                            |  1 -
 .../laf/ScreenMenu/ScreenMenuMemoryLeakTest.java    | 13 ++++++-------
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt
index c996324fd50..04f8ba03973 100644
--- a/test/jdk/ProblemList.txt
+++ b/test/jdk/ProblemList.txt
@@ -751,7 +751,6 @@ javax/swing/JPopupMenu/8075063/ContextMenuScrollTest.java 202880 linux-all
 javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765  macosx-all,linux-all
 javax/swing/plaf/nimbus/8057791/bug8057791.java 8202877 macosx-all
 javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
-com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java 8202878 macosx-all
 java/awt/im/memoryleak/InputContextMemoryLeakTest.java 8023814 linux-all,solaris-all
 
 
diff --git a/test/jdk/com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java b/test/jdk/com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java
index bfb8580d4c5..e30ee380d48 100644
--- a/test/jdk/com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java
+++ b/test/jdk/com/apple/laf/ScreenMenu/ScreenMenuMemoryLeakTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -24,9 +24,11 @@
 /**
  * @test
  * @key headful
- * @bug 8158325 8180821
+ * @bug 8158325 8180821 8202878
  * @summary Memory leak in com.apple.laf.ScreenMenu: removed JMenuItems are still referenced
  * @requires (os.family == "mac")
+ * @library /javax/swing/regtesthelpers
+ * @build Util
  * @run main/timeout=300/othervm -Xmx16m ScreenMenuMemoryLeakTest
  */
 
@@ -44,8 +46,6 @@ import javax.swing.WindowConstants;
 
 public class ScreenMenuMemoryLeakTest {
 
-    private static byte[] sBytes;
-
     private static WeakReference<JMenuItem> sMenuItem;
     private static JFrame sFrame;
     private static JMenu sMenu;
@@ -65,9 +65,8 @@ public class ScreenMenuMemoryLeakTest {
                 removeMenuItemFromMenu();
             }
         });
-        System.gc();
-        System.runFinalization();
-        Thread.sleep(1000);
+
+        Util.generateOOME();
         JMenuItem menuItem = sMenuItem.get();
         EventQueue.invokeAndWait(new Runnable() {
             @Override