View | Details | Raw Unified | Return to bug 212262 | Differences between
and this patch

Collapse All | Expand All

(-)defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader.java (-2 / +23 lines)
Lines 12-17 Link Here
12
package org.eclipse.osgi.internal.baseadaptor;
12
package org.eclipse.osgi.internal.baseadaptor;
13
13
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.lang.reflect.Method;
15
import java.net.MalformedURLException;
16
import java.net.MalformedURLException;
16
import java.net.URL;
17
import java.net.URL;
17
import java.security.*;
18
import java.security.*;
Lines 29-52 Link Here
29
import org.osgi.framework.Bundle;
30
import org.osgi.framework.Bundle;
30
31
31
/**
32
/**
32
 * The default implemention of <code>BaseClassLoader</code>.  This implementation extends
33
 * The default implementation of <code>BaseClassLoader</code>.  This implementation extends
33
 * <code>ClassLoader</code>.
34
 * <code>ClassLoader</code>.
34
 * @see BaseClassLoader
35
 * @see BaseClassLoader
35
 * @see ClasspathManager
36
 * @see ClasspathManager
36
 */
37
 */
37
public class DefaultClassLoader extends ClassLoader implements BaseClassLoader {
38
public class DefaultClassLoader extends ClassLoader implements ParallelClassLoader {
38
	/**
39
	/**
39
	 * A PermissionCollection for AllPermissions; shared across all ProtectionDomains when security is disabled
40
	 * A PermissionCollection for AllPermissions; shared across all ProtectionDomains when security is disabled
40
	 */
41
	 */
41
	protected static final PermissionCollection ALLPERMISSIONS;
42
	protected static final PermissionCollection ALLPERMISSIONS;
42
	private final static String CLASS_CERTIFICATE_SUPPORT = "osgi.support.class.certificate"; //$NON-NLS-1$
43
	private final static String CLASS_CERTIFICATE_SUPPORT = "osgi.support.class.certificate"; //$NON-NLS-1$
44
	private final static String CLASS_LOADER_TYPE = "osgi.classloader.type"; //$NON-NLS-1$
45
	private final static String CLASS_LOADER_TYPE_PARALLEL = "parallel"; //$NON-NLS-1$
43
	private static final boolean CLASS_CERTIFICATE;
46
	private static final boolean CLASS_CERTIFICATE;
47
	private static final boolean PARALLEL_CAPABLE;
44
	static {
48
	static {
45
		CLASS_CERTIFICATE = Boolean.valueOf(FrameworkProperties.getProperty(CLASS_CERTIFICATE_SUPPORT, "true")).booleanValue(); //$NON-NLS-1$
49
		CLASS_CERTIFICATE = Boolean.valueOf(FrameworkProperties.getProperty(CLASS_CERTIFICATE_SUPPORT, "true")).booleanValue(); //$NON-NLS-1$
46
		AllPermission allPerm = new AllPermission();
50
		AllPermission allPerm = new AllPermission();
47
		ALLPERMISSIONS = allPerm.newPermissionCollection();
51
		ALLPERMISSIONS = allPerm.newPermissionCollection();
48
		if (ALLPERMISSIONS != null)
52
		if (ALLPERMISSIONS != null)
49
			ALLPERMISSIONS.add(allPerm);
53
			ALLPERMISSIONS.add(allPerm);
54
		boolean typeParallel = CLASS_LOADER_TYPE_PARALLEL.equals(FrameworkProperties.getProperty(CLASS_LOADER_TYPE));
55
		boolean parallelCapable = false;
56
		try {
57
			if (typeParallel) {
58
				Method parallelCapableMetod = ClassLoader.class.getDeclaredMethod("registerAsParallelCapable", null); //$NON-NLS-1$
59
				parallelCapableMetod.setAccessible(true);
60
				parallelCapable = ((Boolean) parallelCapableMetod.invoke(null, null)).booleanValue();
61
			}
62
		} catch (Throwable e) {
63
			// must do everything to avoid failing in clinit
64
			parallelCapable = false;
65
		}
66
		PARALLEL_CAPABLE = parallelCapable;
50
	}
67
	}
51
68
52
	protected ClassLoaderDelegate delegate;
69
	protected ClassLoaderDelegate delegate;
Lines 250-253 Link Here
250
	public Bundle getBundle() {
267
	public Bundle getBundle() {
251
		return manager.getBaseData().getBundle();
268
		return manager.getBaseData().getBundle();
252
	}
269
	}
270
271
	public boolean isParallelCapable() {
272
		return PARALLEL_CAPABLE;
273
	}
253
}
274
}
(-)supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java (+3 lines)
Lines 554-559 Link Here
554
			if (error)
554
			if (error)
555
				fileStream.abort();
555
				fileStream.abort();
556
		}
556
		}
557
558
		if (openCleanup)
559
			cleanup();
557
		tableStamp = ReliableFile.lastModifiedVersion(tableFile);
560
		tableStamp = ReliableFile.lastModifiedVersion(tableFile);
558
	}
561
	}
559
562
(-)defaultAdaptor/src/org/eclipse/osgi/baseadaptor/loader/ClasspathManager.java (-1 / +3 lines)
Lines 56-61 Link Here
56
	// a collection of String[2], each element is {"libname", "libpath"}
56
	// a collection of String[2], each element is {"libname", "libpath"}
57
	private Collection loadedLibraries = null;
57
	private Collection loadedLibraries = null;
58
	private HashMap classNameLocks = new HashMap(5);
58
	private HashMap classNameLocks = new HashMap(5);
59
	private final boolean isParallelClassLoader;
59
60
60
	/**
61
	/**
61
	 * Constructs a classpath manager for the given host base data, classpath and base class loader
62
	 * Constructs a classpath manager for the given host base data, classpath and base class loader
Lines 67-72 Link Here
67
		this.data = data;
68
		this.data = data;
68
		this.classpath = classpath;
69
		this.classpath = classpath;
69
		this.classloader = classloader;
70
		this.classloader = classloader;
71
		isParallelClassLoader = (classloader instanceof ParallelClassLoader) ? ((ParallelClassLoader) classloader).isParallelCapable() : false;
70
	}
72
	}
71
73
72
	/**
74
	/**
Lines 437-443 Link Here
437
		try {
439
		try {
438
			for (int i = 0; i < hooks.length; i++)
440
			for (int i = 0; i < hooks.length; i++)
439
				hooks[i].preFindLocalClass(classname, this);
441
				hooks[i].preFindLocalClass(classname, this);
440
			if (LOCK_CLASSNAME)
442
			if (LOCK_CLASSNAME || isParallelClassLoader)
441
				result = findLocalClass_LockClassName(classname, hooks);
443
				result = findLocalClass_LockClassName(classname, hooks);
442
			else
444
			else
443
				result = findLocalClass_LockClassLoader(classname, hooks);
445
				result = findLocalClass_LockClassLoader(classname, hooks);
(-)defaultAdaptor/src/org/eclipse/osgi/baseadaptor/loader/ParallelClassLoader.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.osgi.baseadaptor.loader;
13
14
/**
15
 * A parallel class loader.  Parallel class loaders are thread safe class loaders
16
 * which can handle multiple threads loading classes and resources from them at 
17
 * the same time.  This is important for OSGi class loaders because the 
18
 * class loader delegate in OSGi is not strictly hierarchical, instead the 
19
 * delegation is grid based and may have cycles.
20
 * <p>
21
 * The {@link ClasspathManager} handles parallel capable class loaders 
22
 * differently from other class loaders.  For parallel capable 
23
 * class loaders when {@link ClasspathManager#findLocalClass(String)} is 
24
 * called a lock will be obtained for the class name being searched while 
25
 * calling {@link BaseClassLoader#publicFindLoaded(String)} and 
26
 * {@link BaseClassLoader#defineClass(String, byte[], ClasspathEntry, org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry)}.
27
 * This prevents other threads from trying to searching for the same class at the
28
 * same time.  For other class loaders the class loader lock is obtained 
29
 * instead.  This prevents other threads from trying to search for any 
30
 * class while the lock is held. 
31
 * </p>
32
 * <p>
33
 * <b>Note:</b> This interface is part of an interim API that is still under 
34
 * development. It is being made available at this early stage to solicit feedback 
35
 * from pioneering adopters on the understanding that any code that uses this API will may 
36
 * be broken (repeatedly) as the API evolves.
37
 * </p>
38
 * @since 3.5
39
 */
40
public interface ParallelClassLoader extends BaseClassLoader {
41
	/**
42
	 * Indicates if this class loader is parallel capable.  Even
43
	 * if a class loader is able to be parallel capable there are some
44
	 * restrictions imposed by the VM which may prevent a class loader 
45
	 * from being parallel capable.  For example, some VMs may lock 
46
	 * the class loader natively before delegating to a class loader.
47
	 * This type of locking will prevent a class loader from being 
48
	 * parallel capable.
49
	 * @return true if this class loader is parallel capable; false otherwise.
50
	 */
51
	boolean isParallelCapable();
52
}

Return to bug 212262