mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 12:32:15 +00:00
merged with the latest trunk
This commit is contained in:
commit
e17760256e
3385 files changed
+75595
-32200
No files matched your search
@@ -33,10 +33,12 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.Scope;
|
||||
import com.google.inject.Scopes;
|
||||
import com.google.inject.name.Names;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import hudson.init.InitMilestone;
|
||||
import hudson.model.Hudson;
|
||||
import jenkins.model.Jenkins;
|
||||
import net.java.sezpoz.Index;
|
||||
import net.java.sezpoz.IndexItem;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.Descriptor;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.NoExternalUse;
|
||||
|
||||
@@ -71,7 +73,7 @@ import java.lang.reflect.Method;
|
||||
public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
/**
|
||||
* @deprecated as of 1.356
|
||||
* Use and implement {@link #find(Class, Hudson)} that allows us to put some metadata.
|
||||
* Use and implement {@link #find(Class,Hudson)} that allows us to put some metadata.
|
||||
*/
|
||||
@Restricted(NoExternalUse.class)
|
||||
public <T> Collection<T> findExtensions(Class<T> type, Hudson hudson) {
|
||||
@@ -94,12 +96,12 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
* @return
|
||||
* Can be empty but never null.
|
||||
* @since 1.356
|
||||
* Older implementations provide {@link #findExtensions(Class, Hudson)}
|
||||
* Older implementations provide {@link #findExtensions(Class,Hudson)}
|
||||
*/
|
||||
public abstract <T> Collection<ExtensionComponent<T>> find(Class<T> type, Hudson hudson);
|
||||
|
||||
/**
|
||||
* A pointless function to work around what appears to be a HotSpot problem. See HUDSON-5756 and bug 6933067
|
||||
* A pointless function to work around what appears to be a HotSpot problem. See JENKINS-5756 and bug 6933067
|
||||
* on BugParade for more details.
|
||||
*/
|
||||
public <T> Collection<ExtensionComponent<T>> _find(Class<T> type, Hudson hudson) {
|
||||
@@ -121,13 +123,13 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
* <p>
|
||||
* In the mean time, another thread can load and initialize a class, and that initialization
|
||||
* can eventually results in listing up extensions, for example through static initializer.
|
||||
* Such activitiy locks class initialization first, then locks extension list.
|
||||
* Such activity locks class initialization first, then locks extension list.
|
||||
*
|
||||
* <p>
|
||||
* This inconsistent locking order results in a dead lock, you see.
|
||||
*
|
||||
* <p>
|
||||
* So to reduce the likelihood, this method is called in prior to {@link #find(Class, Hudson)} invocation,
|
||||
* So to reduce the likelihood, this method is called in prior to {@link #find(Class,Hudson)} invocation,
|
||||
* but from outside the lock. The implementation is expected to perform all the class initialization activities
|
||||
* from here.
|
||||
*
|
||||
@@ -306,11 +308,33 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
* Uses Sezpoz as the underlying mechanism.
|
||||
*/
|
||||
public static final class Sezpoz extends ExtensionFinder {
|
||||
|
||||
private volatile List<IndexItem<Extension,Object>> indices;
|
||||
|
||||
/**
|
||||
* Loads indices (ideally once but as few times as possible), then reuse them later.
|
||||
* {@link ExtensionList#ensureLoaded()} guarantees that this method won't be called until
|
||||
* {@link InitMilestone#PLUGINS_PREPARED} is attained, so this method is guaranteed to
|
||||
* see all the classes and indices.
|
||||
*/
|
||||
private List<IndexItem<Extension,Object>> getIndices() {
|
||||
// this method cannot be synchronized because of a dead lock possibility in the following order of events:
|
||||
// 1. thread X can start listing indices, locking this object 'SZ'
|
||||
// 2. thread Y starts loading a class, locking a classloader 'CL'
|
||||
// 3. thread X needs to load a class, now blocked on CL
|
||||
// 4. thread Y decides to load extensions, now blocked on SZ.
|
||||
// 5. dead lock
|
||||
if (indices==null) {
|
||||
ClassLoader cl = Jenkins.getInstance().getPluginManager().uberClassLoader;
|
||||
indices = ImmutableList.copyOf(Index.load(Extension.class, Object.class, cl));
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
|
||||
public <T> Collection<ExtensionComponent<T>> find(Class<T> type, Hudson hudson) {
|
||||
List<ExtensionComponent<T>> result = new ArrayList<ExtensionComponent<T>>();
|
||||
|
||||
ClassLoader cl = hudson.getPluginManager().uberClassLoader;
|
||||
for (IndexItem<Extension,Object> item : Index.load(Extension.class, Object.class, cl)) {
|
||||
for (IndexItem<Extension,Object> item : getIndices()) {
|
||||
try {
|
||||
AnnotatedElement e = item.element();
|
||||
Class<?> extType;
|
||||
@@ -333,11 +357,9 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
} catch (LinkageError e) {
|
||||
// sometimes the instantiation fails in an indirect classloading failure,
|
||||
// which results in a LinkageError
|
||||
LOGGER.log(item.annotation().optional() ? Level.FINE : Level.WARNING,
|
||||
"Failed to load "+item.className(), e);
|
||||
LOGGER.log(logLevel(item), "Failed to load "+item.className(), e);
|
||||
} catch (InstantiationException e) {
|
||||
LOGGER.log(item.annotation().optional() ? Level.FINE : Level.WARNING,
|
||||
"Failed to load "+item.className(), e);
|
||||
LOGGER.log(logLevel(item), "Failed to load "+item.className(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,9 +368,12 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
|
||||
@Override
|
||||
public void scout(Class extensionType, Hudson hudson) {
|
||||
ClassLoader cl = hudson.getPluginManager().uberClassLoader;
|
||||
for (IndexItem<Extension,Object> item : Index.load(Extension.class, Object.class, cl)) {
|
||||
for (IndexItem<Extension,Object> item : getIndices()) {
|
||||
try {
|
||||
// we might end up having multiple threads concurrently calling into element(),
|
||||
// but we can't synchronize this --- if we do, the one thread that's supposed to load a class
|
||||
// can block while other threads wait for the entry into the element call().
|
||||
// looking at the sezpoz code, it should be safe to do so
|
||||
AnnotatedElement e = item.element();
|
||||
Class<?> extType;
|
||||
if (e instanceof Class) {
|
||||
@@ -361,19 +386,22 @@ public abstract class ExtensionFinder implements ExtensionPoint {
|
||||
extType = ((Method)e).getReturnType();
|
||||
} else
|
||||
throw new AssertionError();
|
||||
// accroding to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459208
|
||||
// according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6459208
|
||||
// this appears to be the only way to force a class initialization
|
||||
Class.forName(extType.getName(),true,extType.getClassLoader());
|
||||
} catch (InstantiationException e) {
|
||||
LOGGER.log(item.annotation().optional() ? Level.FINE : Level.WARNING,
|
||||
"Failed to scout "+item.className(), e);
|
||||
LOGGER.log(logLevel(item), "Failed to scout "+item.className(), e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOGGER.log(Level.WARNING,"Failed to scout "+item.className(), e);
|
||||
LOGGER.log(logLevel(item), "Failed to scout "+item.className(), e);
|
||||
} catch (LinkageError e) {
|
||||
LOGGER.log(Level.WARNING,"Failed to scout "+item.className(), e);
|
||||
LOGGER.log(logLevel(item), "Failed to scout "+item.className(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Level logLevel(IndexItem<Extension, Object> item) {
|
||||
return item.annotation().optional() ? Level.FINE : Level.WARNING;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(ExtensionFinder.class.getName());
|
||||
|
||||
Reference in new issue
Block a user