-
Notifications
You must be signed in to change notification settings - Fork 736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable late attach to self by default #158
Conversation
83ecb72
to
47ed307
Compare
@DanHeidinga do you have any comments further to those in pull request #18? |
* but parse it lazily because we rarely need the value. | ||
*/ | ||
public final static String allowAttachSelf = | ||
com.ibm.oti.vm.VM.getVMLangAccess().internalGetProperties().getProperty("jdk.attach.allowAttachSelf"); //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to import com.ibm.oti.vm
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Historical reasons. Fixed.
Also cleaned up warnings on Java 5-era code.
* @param vmArgs VM arguments | ||
* @param appArgs Application arguments | ||
*/ | ||
public TargetManager(String cmdName, String targetId, String displayName, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new code, please don't wrap at ~80 chars. The code is way more readable with longer lines then with arbitrary breaks to limit line length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was cloned from the old Target manager, but fixed anyway.
* This test must be invoked via testng. Running the main method will return only the status of the attach API. | ||
* | ||
*/ | ||
@SuppressWarnings({"nls","boxing"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address the NLS and boxing warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Missed that one.
/** | ||
* Reads any available lines of text from a stream without blocking, | ||
* except to find the terminating newline. | ||
* This assumes the producer emits complete lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready()
returns true as soon as a read()
operation won't block - i.e.: a single character is available. This comment makes assumptions that aren't guaranteed by the Class libraries.
The usual way to do this is with separate threads that read from the buffered reader and append lines to some shared data structure.
Is there something I'm missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed deskside with Peter. This isn't new code per se, its moving old code to a new location. I'm willing to live it, especially as it's functioned for the past ~8 years.
We should take a hard look at some of this code when the Java 8 vs 9 vs next test code is rationalized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new code, I agree with the suggestion. However, as discussed, this is cloned legacy code which we have been running for ~9 years. Rewriting it now would add risk to this changeset.
I would be happy to re-do this code (and the Java8AndUp TargetManager) if you would open an issue.
8920243
to
f490329
Compare
Changeset updated. |
Are any further changes required? |
I'm at JavaOne this week and likely won't get a chance to finish the review until next week. I have no objections to one of the other committers completing the review / merge. |
f490329
to
45c2066
Compare
Are any further changes required? |
@DanHeidinga Do you have any other comments on this pull request? |
@@ -50,7 +52,7 @@ | |||
/** | |||
* Time delay before we give up trying to terminate the wait loop. | |||
*/ | |||
static final long shutdownTimeoutMs = Integer.getInteger("com.ibm.tools.attach.shutdown_timeout", 10000); //$NON-NLS-1$ | |||
static final long shutdownTimeoutMs = Integer.getInteger("com.ibm.tools.attach.shutdown_timeout", 10000).longValue(); //$NON-NLS-1$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of the point of this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It avoids a warning about auto-unboxing.
@@ -0,0 +1,67 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2015, 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is new code the start date should be 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,103 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2001, 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is new code the start date should be 2017.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,30 @@ | |||
/* Copyright (c) 2015, 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is new code the start date should 2017.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,30 @@ | |||
/* Copyright (c) 2015, 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is new code the start date should 2017.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -0,0 +1,412 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2001, 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is new code the start date should be 2017.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
* or the Apache License, Version 2.0 which accompanies this distribution and | ||
* is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* This Source Code is also Distributed under one or more Secondary Licenses, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new files all have the incorrect license.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Let me know if I missed any.
logger.debug("javaExec="+javaExec); | ||
|
||
/* These are the VM options to the parent process, which we wish to pass on to the child. */ | ||
String sideCar = System.getProperty("java.sidecar"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"java.sidecar" is obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this is set by the playlist to indicate VM settings required by child processes (see test/Java8andUp/playlist.xml). Should I use a different system property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I though it was a reference to something old and obsolete.
@@ -102,10 +110,20 @@ | |||
private static String nameProperty; | |||
private static String pidProperty; | |||
private static int numberOfTargets; | |||
/*[IF Sidecar19-SE]*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be useful to add this code to Java 8 as well, but making the default true instead of false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done
d59dfed
to
db3c6cb
Compare
@@ -1262,3 +1262,4 @@ K0644="Caller-sensitive method called StackWalker.getCallerClass()" | |||
#java.lang.ClassLoader | |||
K0645="The given class loader name can't be empty." | |||
|
|||
K0646="Late attach connection to self disabled. Set jdk.attach.allowAttachSelf=true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the preprocessor definition to match.
/******************************************************************************* | ||
* Copyright (c) 2017 IBM Corp. and others | ||
* | ||
* This program and the accompanying materials are made available under |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update all the licenses to be the lastest version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears the middle part of the licenses was updated, but not the ending part.
@@ -0,0 +1,68 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2017 IBM Corp. and others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 2017, 2017 in order to pass the copyright check.
@llxia any concerns with the test code? |
@llxia or @sophia-guo Further to @pshipton 's comment above, is there a way I can share utility classes between the Java8AndUp and Java9AndUp projects? That would simplify this PR considerably. Thanks |
db3c6cb
to
fe52e1c
Compare
Copyrights and NLS message updated. |
Further to discussion with @smlambert et al, I will create a test utilities directory (under s separate pull request) to hold common code. When that is complete, this pull request will be updated to use utilities in the common directory. |
fe52e1c
to
9f927e2
Compare
Pull request updated:
Thanks |
public static void main(String[] args) { | ||
try { | ||
String myId = VmIdGetter.getVmId(); | ||
System.err.println("myId="+myId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid stray system.out / system.err calls in test code and use logger instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SelfAttacher is actually a child process. It uses stderr to communicate its process ID (and hence VM ID) to the target manager. I will add a comment to that effect.
e.printStackTrace(); | ||
System.exit(ATTACH_ERROR_CODE); | ||
} | ||
System.exit(ATTACH_SELF_API_SUCCEEDED_CODE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not think the System.exit calls are appropriate above, assert is likely what you should be doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the exit code to indicate the result of the late attach attempt to the parent test process, i.e.
int status = target.waitFor();
assertEquals(status, ATTACH_SELF_API_SUCCEEDED_CODE, "wrong exit status");
Again, will add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have stepped back and viewed the entire suite of attach API tests to see. Comments will be useful thanks.
} | ||
|
||
@Test | ||
public void testAllowAttachSelfDisnable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable vs Disnable in method name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Thanks for catching that.
Arrays.asList(new String[] {ATTACH_ENABLE_PROPERTY, ATTACH_SELF_ENABLE_PROPERTY+"=false"}), null); | ||
try { | ||
int status = target.waitFor(); | ||
assertEquals(status, ATTACH_SELF_IOEXCEPTION_CODE, "wrong exit status"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An opportunity for a better error message that wrong exit status (include exit status in the message would aid triage).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertEquals() already does that, e.g.
wrong exit status expected [2] but found [1]
*******************************************************************************/ | ||
package org.openj9.test.attachAPI; | ||
/* This class is separated from the main test because we need two | ||
* copies to accommodate old and new versions of ProcessHandle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pshipton src_current is for supporting old class library version, which I thought we were trying to move from, instead of build up more test/support for. Any guidance on this, why we keep adding more test material into this effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to work on the vmfarm builds, which are stuck on an old (incompatible) class library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is adding a new test to IBM internal Java 9 b148 builds, correct? I agree its not necessary to add new testing. Existing testing either needs to be fixed or removed to keep the builds green. The b148 builds are obsolete and will be deleted once the equivalent testing is running on OpenJ9.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with the FV team, the tooling doesn't allow us to add the test only for the "latest" (i.e. post b148) JCL, so we will need to maintain 2 copies of some classes (as is done with the StackWalker tests) until we can kill b148.
public static void main(String[] args) { | ||
try { | ||
String myId = VmIdGetter.getVmId(); | ||
System.err.println("myId="+myId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we should logger here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, but no, see above.
return myId; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put this file in test/Java9andUp/src to avoid duplication in both ssrc_latset and src_current.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly no. the ProcessHandle API changed from getPid() to pid();
Testing changes now. Stay tuned... |
adbcb58
to
5f3b64e
Compare
This addresses openj9 issue eclipse-openj9#126 Prevent a JVM from late attaching to itself unless the system property "jdk.attach.allowAttachSelf" is set either to "true" or an empty string, per the reference implementation. Enforce this in Java 9 only. Update existing tests to enable this feature by default so they will continue to run. Add new Java 9 tests to exercise this feature. Signed-off-by: Peter Bain <[email protected]>
5f3b64e
to
609fe3e
Compare
Personal build passed. @smlambert any more concerns? |
Jenkins test extended |
failed tests due to known unrelated issue: org.openj9.test.vmArguments.VmArgumentTests.testCrNocr |
Restore legacy AttachAPI methods
This addresses openj9 issue #126
fixes #126
Prevent a JVM from late attaching to itself unless the system property
"jdk.attach.allowAttachSelf" is set either to "true" or an empty string, per
the reference implementation. Enforce this in Java 9 only. Update existing
tests to enable this feature by default so they will continue to run. Add new
Java 9 tests to exercise this feature.
Signed-off-by: Peter Bain [email protected]