8072395: sun/tools/jmap/heapconfig/LingeredAppTest.java and sun/tools/jmap/heapconfig/JMapHeapConfigTest.java fail due to LingeredApp ERROR: java.io.IOException: Lock is too old. Aborting

Remove lock age check

Reviewed-by: sla, dholmes, kevinw
This commit is contained in:
Dmitry Samersoff 2015-02-18 03:45:06 -08:00
parent 7168bf102d
commit eaa8d1e0f3
4 changed files with 164 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2015, 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
@ -22,13 +22,20 @@
*/
package jdk.testlibrary;
import java.util.regex.Pattern;
import java.io.RandomAccessFile;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Platform {
private static final String osName = System.getProperty("os.name");
private static final String dataModel = System.getProperty("sun.arch.data.model");
private static final String vmVersion = System.getProperty("java.vm.version");
private static final String javaVersion = System.getProperty("java.version");
private static final String osArch = System.getProperty("os.arch");
private static final String vmName = System.getProperty("java.vm.name");
private static final String userName = System.getProperty("user.name");
private static final String compiler = System.getProperty("sun.management.compiler");
public static boolean isClient() {
return vmName.endsWith(" Client VM");
@ -38,6 +45,23 @@ public class Platform {
return vmName.endsWith(" Server VM");
}
public static boolean isGraal() {
return vmName.endsWith(" Graal VM");
}
public static boolean isMinimal() {
return vmName.endsWith(" Minimal VM");
}
public static boolean isEmbedded() {
return vmName.contains("Embedded");
}
public static boolean isTieredSupported() {
return compiler.contains("Tiered Compilers");
}
public static boolean is32bit() {
return dataModel.equals("32");
}
@ -46,20 +70,24 @@ public class Platform {
return dataModel.equals("64");
}
public static boolean isSolaris() {
return isOs("sunos");
public static boolean isAix() {
return isOs("aix");
}
public static boolean isWindows() {
return isOs("win");
public static boolean isLinux() {
return isOs("linux");
}
public static boolean isOSX() {
return isOs("mac");
}
public static boolean isLinux() {
return isOs("linux");
public static boolean isSolaris() {
return isOs("sunos");
}
public static boolean isWindows() {
return isOs("win");
}
private static boolean isOs(String osname) {
@ -71,7 +99,8 @@ public class Platform {
}
public static boolean isDebugBuild() {
return vmVersion.toLowerCase().contains("debug");
return (vmVersion.toLowerCase().contains("debug") ||
javaVersion.toLowerCase().contains("debug"));
}
public static String getVMVersion() {
@ -80,33 +109,101 @@ public class Platform {
// Returns true for sparc and sparcv9.
public static boolean isSparc() {
return isArch("sparc");
return isArch("sparc.*");
}
public static boolean isARM() {
return isArch("arm");
return isArch("arm.*");
}
public static boolean isPPC() {
return isArch("ppc");
return isArch("ppc.*");
}
public static boolean isX86() {
// On Linux it's 'i386', Windows 'x86'
return (isArch("i386") || isArch("x86"));
// On Linux it's 'i386', Windows 'x86' without '_64' suffix.
return isArch("(i386)|(x86(?!_64))");
}
public static boolean isX64() {
// On OSX it's 'x86_64' and on other (Linux, Windows and Solaris) platforms it's 'amd64'
return (isArch("amd64") || isArch("x86_64"));
return isArch("(amd64)|(x86_64)");
}
private static boolean isArch(String archname) {
return osArch.toLowerCase().startsWith(archname.toLowerCase());
private static boolean isArch(String archnameRE) {
return Pattern.compile(archnameRE, Pattern.CASE_INSENSITIVE)
.matcher(osArch)
.matches();
}
public static String getOsArch() {
return osArch;
}
/**
* Return a boolean for whether we expect to be able to attach
* the SA to our own processes on this system.
*/
public static boolean shouldSAAttach()
throws IOException {
if (isAix()) {
return false; // SA not implemented.
} else if (isLinux()) {
return canPtraceAttachLinux();
} else if (isOSX()) {
return canAttachOSX();
} else {
// Other platforms expected to work:
return true;
}
}
/**
* On Linux, first check the SELinux boolean "deny_ptrace" and return false
* as we expect to be denied if that is "1".
*/
public static boolean canPtraceAttachLinux()
throws IOException {
// SELinux deny_ptrace:
try(RandomAccessFile file = new RandomAccessFile("/sys/fs/selinux/booleans/deny_ptrace", "r")) {
if (file.readByte() != '0') {
return false;
}
}
catch(FileNotFoundException ex) {
// Ignored
}
// YAMA enhanced security ptrace_scope:
// 0 - a process can PTRACE_ATTACH to any other process running under the same uid
// 1 - restricted ptrace: a process must be a children of the inferior or user is root
// 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root
// 3 - no attach: no processes may use ptrace with PTRACE_ATTACH
try(RandomAccessFile file = new RandomAccessFile("/proc/sys/kernel/yama/ptrace_scope", "r")) {
byte yama_scope = file.readByte();
if (yama_scope == '3') {
return false;
}
if (!userName.equals("root") && yama_scope != '0') {
return false;
}
}
catch(FileNotFoundException ex) {
// Ignored
}
// Otherwise expect to be permitted:
return true;
}
/**
* On OSX, expect permission to attach only if we are root.
*/
public static boolean canAttachOSX() {
return userName.equals("root");
}
}

View File

@ -37,6 +37,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jdk.testlibrary.Utils;
import jdk.testlibrary.Platform;
public class JMapHeapConfigTest {
@ -109,9 +110,21 @@ public class JMapHeapConfigTest {
}
}
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
System.out.println("Starting JMapHeapConfigTest");
if (!Platform.shouldSAAttach()) {
// Silently skip the test if we don't have enough permissions to attach
System.err.println("Error! Insufficient permissions to attach.");
return;
}
if (!LingeredApp.isLastModifiedWorking()) {
// Exact behaviour of the test depends to operating system and the test nature,
// so just print the warning and continue
System.err.println("Warning! Last modified time doesn't work.");
}
boolean mx_found = false;
List<String> jvmOptions = Utils.getVmOptions();
for (String option : jvmOptions) {

View File

@ -362,6 +362,41 @@ public class LingeredApp {
}
}
/**
* LastModified time might not work correctly in some cases it might
* cause later failures
*/
public static boolean isLastModifiedWorking() {
boolean sane = true;
try {
long lm = lastModified(".");
if (lm == 0) {
System.err.println("SANITY Warning! The lastModifiedTime() doesn't work on this system, it returns 0");
sane = false;
}
long now = epoch();
if (lm > now) {
System.err.println("SANITY Warning! The Clock is wrong on this system lastModifiedTime() > getTime()");
sane = false;
}
setLastModified(".", epoch());
long lm1 = lastModified(".");
if (lm1 <= lm) {
System.err.println("SANITY Warning! The setLastModified doesn't work on this system");
sane = false;
}
}
catch(IOException e) {
System.err.println("SANITY Warning! IOException during sanity check " + e);
sane = false;
}
return sane;
}
/**
* This part is the application it self
*/
@ -378,16 +413,8 @@ public class LingeredApp {
Path path = Paths.get(theLockFileName);
while (Files.exists(path)) {
long lm = lastModified(theLockFileName);
long now = epoch();
// A bit of paranoja, don't allow test app to run more than an hour
if (now - lm > 3600) {
throw new IOException("Lock is too old. Aborting");
}
// Touch lock to indicate our rediness
setLastModified(theLockFileName, now);
// Touch the lock to indicate our readiness
setLastModified(theLockFileName, epoch());
Thread.sleep(spinDelay);
}

View File

@ -31,8 +31,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LingeredAppTest {