diff --git a/langtools/test/tools/lib/ToolBox.java b/langtools/test/tools/lib/ToolBox.java
index 2d6d0cd555b..d77e84c26b7 100644
--- a/langtools/test/tools/lib/ToolBox.java
+++ b/langtools/test/tools/lib/ToolBox.java
@@ -273,6 +273,34 @@ public class ToolBox {
             Files.delete(Paths.get(file));
     }
 
+    /**
+     * Deletes all content of a directory (but not the directory itself).
+     * @param root the directory to be cleaned
+     */
+    public void cleanDirectory(Path root) throws IOException {
+        if (!Files.isDirectory(root)) {
+            throw new IOException(root + " is not a directory");
+        }
+        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult visitFile(Path file, BasicFileAttributes a) throws IOException {
+                Files.delete(file);
+                return FileVisitResult.CONTINUE;
+            }
+
+            @Override
+            public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
+                if (e != null) {
+                    throw e;
+                }
+                if (!dir.equals(root)) {
+                    Files.delete(dir);
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+
     /**
      * Moves a file.
      * If the given destination exists and is a directory, the file will be moved
diff --git a/langtools/test/tools/sjavac/CompileCircularSources.java b/langtools/test/tools/sjavac/CompileCircularSources.java
index 3014531398d..9634271b97f 100644
--- a/langtools/test/tools/sjavac/CompileCircularSources.java
+++ b/langtools/test/tools/sjavac/CompileCircularSources.java
@@ -36,6 +36,7 @@
  * @run main Wrapper CompileCircularSources
  */
 
+import java.io.IOException;
 import java.util.*;
 import java.nio.file.*;
 
@@ -46,13 +47,11 @@ public class CompileCircularSources extends SJavacTester {
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, BIN);
+        Files.createDirectories(GENSRC);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
                      "package alfa.omega; public class A { beta.B b; }");
         tb.writeFile(GENSRC.resolve("beta/B.java"),
@@ -74,6 +73,5 @@ public class CompileCircularSources extends SJavacTester {
                                      BIN + "/beta/B.class",
                                      BIN + "/gamma/C.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/CompileExcludingDependency.java b/langtools/test/tools/sjavac/CompileExcludingDependency.java
index 2f47e34f2cc..24174f1bfb3 100644
--- a/langtools/test/tools/sjavac/CompileExcludingDependency.java
+++ b/langtools/test/tools/sjavac/CompileExcludingDependency.java
@@ -47,9 +47,7 @@ public class CompileExcludingDependency extends SJavacTester {
 
     // Verify that excluding classes from compilation but not from linking works
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC,BIN);
         Map<String,Long> previous_bin_state = collectState(BIN);
         ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
@@ -69,6 +67,5 @@ public class CompileExcludingDependency extends SJavacTester {
         verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
                                      BIN + "/alfa/omega/A.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/CompileWithAtFile.java b/langtools/test/tools/sjavac/CompileWithAtFile.java
index af0d7ba5a19..1107595cec8 100644
--- a/langtools/test/tools/sjavac/CompileWithAtFile.java
+++ b/langtools/test/tools/sjavac/CompileWithAtFile.java
@@ -46,8 +46,6 @@ public class CompileWithAtFile extends SJavacTester {
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("list.txt"),
                      "-if */alfa/omega/A.java\n" +
                      "-if */beta/B.java\n" +
@@ -55,11 +53,11 @@ public class CompileWithAtFile extends SJavacTester {
                      "-d " + BIN + "\n" +
                      "--state-dir=" + BIN + "\n");
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
-                 "package alfa.omega; import beta.B; public class A { B b; }");
+                     "package alfa.omega; import beta.B; public class A { B b; }");
         tb.writeFile(GENSRC.resolve("beta/B.java"),
-                 "package beta; public class B { }");
+                     "package beta; public class B { }");
         tb.writeFile(GENSRC.resolve("beta/C.java"),
-                 "broken");
+                     "broken");
 
         Files.createDirectory(BIN);
         Map<String,Long> previous_bin_state = collectState(BIN);
@@ -71,6 +69,5 @@ public class CompileWithAtFile extends SJavacTester {
                          BIN + "/javac_state",
                          BIN + "/alfa/omega/A.class",
                          BIN + "/beta/B.class");
-        clean(GENSRC, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/CompileWithInvisibleSources.java b/langtools/test/tools/sjavac/CompileWithInvisibleSources.java
index 16962a80244..099b518217d 100644
--- a/langtools/test/tools/sjavac/CompileWithInvisibleSources.java
+++ b/langtools/test/tools/sjavac/CompileWithInvisibleSources.java
@@ -49,9 +49,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
     // gensrc2 contains broken code in beta.B, thus exclude that package
     // gensrc3 contains a proper beta.B
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, GENSRC2, GENSRC3, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
@@ -82,7 +80,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
                                      BIN + "/javac_state");
 
         System.out.println("----- Compile with exluded beta went well!");
-        clean(BIN);
+        tb.cleanDirectory(BIN);
         compileExpectFailure(GENSRC.toString(),
                              "-sourcepath", GENSRC2.toString(),
                              "-sourcepath", GENSRC3.toString(),
@@ -93,6 +91,5 @@ public class CompileWithInvisibleSources extends SJavacTester {
                              SERVER_ARG);
 
         System.out.println("----- Compile without exluded beta failed, as expected! Good!");
-        clean(GENSRC, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/CompileWithOverrideSources.java b/langtools/test/tools/sjavac/CompileWithOverrideSources.java
index 371075f062f..a010177e634 100644
--- a/langtools/test/tools/sjavac/CompileWithOverrideSources.java
+++ b/langtools/test/tools/sjavac/CompileWithOverrideSources.java
@@ -48,9 +48,7 @@ public class CompileWithOverrideSources extends SJavacTester {
     // Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,
     // only compile ok beta.B in gensrc2
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, GENSRC2, GENSRC3, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
         ToolBox tb = new ToolBox();
@@ -80,7 +78,7 @@ public class CompileWithOverrideSources extends SJavacTester {
                                      BIN + "/javac_state");
 
         System.out.println("----- Compile with exluded beta went well!");
-        clean(BIN);
+        tb.cleanDirectory(BIN);
         compileExpectFailure(GENSRC.toString(),
                              GENSRC2.toString(),
                              "-d", BIN.toString(),
@@ -90,6 +88,5 @@ public class CompileWithOverrideSources extends SJavacTester {
                              SERVER_ARG);
 
         System.out.println("----- Compile without exluded beta failed, as expected! Good!");
-        clean(GENSRC, GENSRC2, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/IncCompileChangeNative.java b/langtools/test/tools/sjavac/IncCompileChangeNative.java
index 40f5c0e4463..aac694e523c 100644
--- a/langtools/test/tools/sjavac/IncCompileChangeNative.java
+++ b/langtools/test/tools/sjavac/IncCompileChangeNative.java
@@ -51,7 +51,6 @@ public class IncCompileChangeNative extends SJavacTester {
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
@@ -59,8 +58,6 @@ public class IncCompileChangeNative extends SJavacTester {
         initialCompile();
         incrementalCompileDropAllNatives();
         incrementalCompileAddNative();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Update B.java with one less native method i.e. it has no longer any methods
diff --git a/langtools/test/tools/sjavac/IncCompileDropClasses.java b/langtools/test/tools/sjavac/IncCompileDropClasses.java
index ec82d6dd8f7..55772f5bc1c 100644
--- a/langtools/test/tools/sjavac/IncCompileDropClasses.java
+++ b/langtools/test/tools/sjavac/IncCompileDropClasses.java
@@ -51,15 +51,12 @@ public class IncCompileDropClasses extends SJavacTester {
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileDroppingClasses();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Testing that deleting AA.java deletes all generated inner class including AA.class
diff --git a/langtools/test/tools/sjavac/IncCompileNoChanges.java b/langtools/test/tools/sjavac/IncCompileNoChanges.java
index 089316d3aa9..ffd1674379f 100644
--- a/langtools/test/tools/sjavac/IncCompileNoChanges.java
+++ b/langtools/test/tools/sjavac/IncCompileNoChanges.java
@@ -50,15 +50,12 @@ public class IncCompileNoChanges  extends SJavacTester {
     Map<String,Long> previous_headers_state;
 
     void test() throws Exception {
-        clean(Paths.get(getClass().getSimpleName()));
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileNoChanges();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Testing that no change in sources implies no change in binaries
diff --git a/langtools/test/tools/sjavac/IncCompileUpdateNative.java b/langtools/test/tools/sjavac/IncCompileUpdateNative.java
index 7801808ae36..7fc7dcb9bc3 100644
--- a/langtools/test/tools/sjavac/IncCompileUpdateNative.java
+++ b/langtools/test/tools/sjavac/IncCompileUpdateNative.java
@@ -51,15 +51,12 @@ public class IncCompileUpdateNative extends SJavacTester {
     ToolBox tb = new ToolBox();
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(GENSRC);
         Files.createDirectories(BIN);
         Files.createDirectories(HEADERS);
 
         initialCompile();
         incrementalCompileChangeNative();
-
-        clean(GENSRC, BIN, HEADERS);
     }
 
     // Update B.java with a new value for the final static annotated with @Native
diff --git a/langtools/test/tools/sjavac/NoState.java b/langtools/test/tools/sjavac/NoState.java
index 11a4adab08f..21322de41ef 100644
--- a/langtools/test/tools/sjavac/NoState.java
+++ b/langtools/test/tools/sjavac/NoState.java
@@ -46,8 +46,6 @@ public class NoState extends SJavacTester {
     }
 
     public void run() throws Exception {
-        clean(TEST_ROOT);
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
         Files.createDirectory(BIN);
         compile("-d", BIN.toString(),
diff --git a/langtools/test/tools/sjavac/PermittedArtifact.java b/langtools/test/tools/sjavac/PermittedArtifact.java
index 8d215d45a2b..f4592129f6a 100644
--- a/langtools/test/tools/sjavac/PermittedArtifact.java
+++ b/langtools/test/tools/sjavac/PermittedArtifact.java
@@ -47,9 +47,7 @@ public class PermittedArtifact extends SJavacTester {
 
     //Verify that --permit-artifact=bin works
     void test() throws Exception {
-        clean(TEST_ROOT);
         Files.createDirectories(BIN);
-        clean(GENSRC, BIN);
 
         Map<String,Long> previous_bin_state = collectState(BIN);
 
@@ -73,6 +71,5 @@ public class PermittedArtifact extends SJavacTester {
                                      BIN + "/alfa/omega/A.class",
                                      BIN + "/alfa/omega/AA.class",
                                      BIN + "/javac_state");
-        clean(GENSRC, BIN);
     }
 }
diff --git a/langtools/test/tools/sjavac/SJavacTester.java b/langtools/test/tools/sjavac/SJavacTester.java
index 1f3ec74885a..3ce59813d6c 100644
--- a/langtools/test/tools/sjavac/SJavacTester.java
+++ b/langtools/test/tools/sjavac/SJavacTester.java
@@ -34,6 +34,7 @@ public class SJavacTester {
             + "portfile=testportfile,"
             + "background=false";
 
+    final ToolBox tb = new ToolBox();
     final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
 
     // Generated sources that will test aspects of sjavac
@@ -53,7 +54,6 @@ public class SJavacTester {
 
     void initialCompile() throws Exception {
         System.out.println("\nInitial compile of gensrc.");
-        ToolBox tb = new ToolBox();
         tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
                      "package alfa.omega; public interface AINT { void aint(); }");
         tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
@@ -101,30 +101,6 @@ public class SJavacTester {
         }
     }
 
-    void delete(final Path root) throws IOException {
-        if (!Files.exists(root)) return;
-        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
-                 @Override
-                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
-                 {
-                     Files.delete(file);
-                     return FileVisitResult.CONTINUE;
-                 }
-
-                 @Override
-                 public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException
-                 {
-                     if (e == null) {
-                         if (!dir.equals(root)) Files.delete(dir);
-                         return FileVisitResult.CONTINUE;
-                     } else {
-                         // directory iteration failed
-                         throw e;
-                     }
-                 }
-            });
-    }
-
     void compile(String... args) throws Exception {
         int rc = Main.go(args);
         if (rc != 0) throw new Exception("Error during compile!");
@@ -265,10 +241,4 @@ public class SJavacTester {
             throw new Exception("The dir should not differ! But it does!");
         }
     }
-
-    void clean(Path... listOfDirs) throws Exception {
-        for (Path dir : listOfDirs) {
-            delete(dir);
-        }
-    }
 }
diff --git a/langtools/test/tools/sjavac/StateDir.java b/langtools/test/tools/sjavac/StateDir.java
index 6e904df6f74..7b1e7fa769a 100644
--- a/langtools/test/tools/sjavac/StateDir.java
+++ b/langtools/test/tools/sjavac/StateDir.java
@@ -46,7 +46,6 @@ public class StateDir extends SJavacTester {
     }
 
     void test() throws Exception {
-        clean(TEST_ROOT);
         Path BAR = TEST_ROOT.resolve("bar");
         Files.createDirectories(BAR);
         Files.createDirectories(BIN);
@@ -69,6 +68,5 @@ public class StateDir extends SJavacTester {
         Map<String,Long> new_bar_state = collectState(BAR);
         verifyThatFilesHaveBeenAdded(previous_bar_state, new_bar_state,
                                      BAR + "/javac_state");
-        clean(GENSRC, BIN, BAR);
     }
 }