Imported Upstream version 5.4.0.167

Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2017-08-21 15:34:15 +00:00
parent e49d6f06c0
commit 536cd135cc
12856 changed files with 563812 additions and 223249 deletions

View File

@ -9,7 +9,9 @@ namespace System.Web.Hosting {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
@ -88,9 +90,6 @@ namespace System.Web.Hosting {
// single instance of app manager
private static ApplicationManager _theAppManager;
// single instance of cache manager
private static CacheManager _cm;
// store fatal exception to assist debugging
private static Exception _fatalException = null;
@ -105,52 +104,6 @@ namespace System.Web.Hosting {
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
}
private void InitCacheManager(long privateBytesLimit) {
if (_cm == null) {
lock (_applicationManagerStaticLock) {
if (_cm == null && !_shutdownInProgress) {
_cm = new CacheManager(this, privateBytesLimit);
}
}
}
}
private void DisposeCacheManager() {
if (_cm != null) {
lock (_applicationManagerStaticLock) {
if (_cm != null) {
_cm.Dispose();
_cm = null;
}
}
}
}
// Each cache must update the total with the difference between it's current size and it's previous size.
// To reduce cross-domain costs, this also returns the updated total size.
internal long GetUpdatedTotalCacheSize(long sizeUpdate) {
CacheManager cm = _cm;
return (cm != null) ? cm.GetUpdatedTotalCacheSize(sizeUpdate) : 0;
}
internal long TrimCaches(int percent) {
long trimmedOrExpired = 0;
Dictionary<string, LockableAppDomainContext> apps = CloneAppDomainsCollection();
foreach (LockableAppDomainContext ac in apps.Values) {
lock (ac) {
HostingEnvironment env = ac.HostEnv;
if (_shutdownInProgress) {
break;
}
if (env == null) {
continue;
}
trimmedOrExpired += env.TrimCache(percent);
}
}
return trimmedOrExpired;
}
internal bool ShutdownInProgress {
get {
return _shutdownInProgress;
@ -468,6 +421,10 @@ namespace System.Web.Hosting {
return GetAppDomain(appID);
}
internal AppDomain GetDefaultAppDomain() {
return AppDomain.CurrentDomain;
}
[SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands", Justification = "This isn't a dangerous method.")]
private string CreateSimpleAppID(IApplicationHost appHost) {
if (appHost == null) {
@ -565,8 +522,6 @@ namespace System.Web.Hosting {
_shutdownInProgress = true;
Dictionary <string, LockableAppDomainContext> oldTable = null;
DisposeCacheManager();
lock (this) {
oldTable = _appDomains;
// don't keep references to hosting environments anymore
@ -769,13 +724,8 @@ namespace System.Web.Hosting {
// communication with hosting environments
//
internal void HostingEnvironmentActivated(long privateBytesLimit) {
internal void HostingEnvironmentActivated() {
int count = Interlocked.Increment(ref _activeHostingEnvCount);
// initialize CacheManager once, without blocking
if (count == 1) {
InitCacheManager(privateBytesLimit);
}
}
internal void HostingEnvironmentShutdownComplete(String appId, IApplicationHost appHost) {
@ -1021,7 +971,7 @@ namespace System.Web.Hosting {
//Hosted by IIS, we already have an IISMap.
if (appHost is ISAPIApplicationHost) {
string cacheKey = System.Web.Caching.CacheInternal.PrefixMapPath + siteID + virtualPath.VirtualPathString;
MapPathCacheInfo cacheInfo = (MapPathCacheInfo)HttpRuntime.CacheInternal.Remove(cacheKey);
MapPathCacheInfo cacheInfo = (MapPathCacheInfo)HttpRuntime.Cache.InternalCache.Remove(cacheKey);
appConfig = WebConfigurationManager.OpenWebConfiguration(appSegment, siteID);
}
// For non-IIS hosting scenarios, we need to get config map from application host in a generic way.
@ -1117,6 +1067,25 @@ namespace System.Web.Hosting {
}
}
// Allow apps to use their own CacheStoreProvider implementations
CacheSection cacheConfig = (CacheSection)appConfig.GetSection("system.web/caching/cache");
if (cacheConfig != null && cacheConfig.DefaultProvider != null && !String.IsNullOrWhiteSpace(cacheConfig.DefaultProvider)) {
ProviderSettingsCollection cacheProviders = cacheConfig.Providers;
if (cacheProviders == null || cacheProviders.Count < 1) {
throw new ProviderException(SR.GetString(SR.Def_provider_not_found));
}
ProviderSettings cacheProviderSettings = cacheProviders[cacheConfig.DefaultProvider];
if (cacheProviderSettings == null) {
throw new ProviderException(SR.GetString(SR.Def_provider_not_found));
} else {
NameValueCollection settings = cacheProviderSettings.Parameters;
settings["name"] = cacheProviderSettings.Name;
settings["type"] = cacheProviderSettings.Type;
appDomainAdditionalData[".defaultObjectCacheProvider"] = settings;
}
}
// If we were launched from a development environment, we might want to enable the application to do things
// it otherwise wouldn't normally allow, such as enabling an administrative control panel. For security reasons,
// we only do this check if <deployment retail="false" /> [the default value] is specified, since the

View File

@ -7,7 +7,10 @@
namespace System.Web.Hosting {
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
@ -31,7 +34,6 @@ namespace System.Web.Hosting {
using System.Web.Util;
using System.Web.WebSockets;
using Microsoft.Win32;
using System.Collections.Generic;
[Flags]
internal enum HostingEnvironmentFlags {
@ -126,6 +128,7 @@ namespace System.Web.Hosting {
private bool _shutdownInProgress;
private String _shutDownStack;
private static NameValueCollection _cacheProviderSettings;
private int _inTrimCache;
private ObjectCacheHost _objectCacheHost;
@ -135,6 +138,7 @@ namespace System.Web.Hosting {
// list of registered IRegisteredObject instances, suspend listeners, and background work items
private Hashtable _registeredObjects = new Hashtable();
private SuspendManager _suspendManager = new SuspendManager();
private ApplicationMonitors _applicationMonitors;
private BackgroundWorkScheduler _backgroundWorkScheduler = null; // created on demand
private static readonly Task<object> _completedTask = Task.FromResult<object>(null);
@ -191,14 +195,29 @@ namespace System.Web.Hosting {
Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler(ApplicationManager.OnUnhandledException);
}
internal long TrimCache(int percent) {
internal static long TrimCache(int percent)
{
if (_theHostingEnvironment != null)
return _theHostingEnvironment.TrimCacheInternal(percent);
return 0;
}
private long TrimCacheInternal(int percent)
{
if (Interlocked.Exchange(ref _inTrimCache, 1) != 0)
return 0;
try {
long trimmedOrExpired = 0;
// do nothing if we're shutting down
if (!_shutdownInitiated) {
trimmedOrExpired = HttpRuntime.CacheInternal.TrimCache(percent);
var iCache = HttpRuntime.Cache.GetInternalCache(createIfDoesNotExist: false);
var oCache = HttpRuntime.Cache.GetObjectCache(createIfDoesNotExist: false);
if (oCache != null) {
trimmedOrExpired = oCache.Trim(percent);
}
if (iCache != null && !iCache.Equals(oCache)) {
trimmedOrExpired += iCache.Trim(percent);
}
if (_objectCacheHost != null && !_shutdownInitiated) {
trimmedOrExpired += _objectCacheHost.TrimCache(percent);
}
@ -330,7 +349,7 @@ namespace System.Web.Hosting {
// notify app manager
if (_appManager != null) {
_appManager.HostingEnvironmentActivated(CacheMemorySizePressure.EffectiveProcessMemoryLimit);
_appManager.HostingEnvironmentActivated();
}
// make sure there is always app host
@ -364,6 +383,8 @@ namespace System.Web.Hosting {
// get application identity (for explicit impersonation mode)
GetApplicationIdentity();
_applicationMonitors = new ApplicationMonitors();
// call AppInitialize, unless the flag says not to do it (e.g. CBM scenario).
// Also, don't call it if HostingInit failed (VSWhidbey 210495)
if(!HttpRuntime.HostingInitFailed) {
@ -1260,6 +1281,19 @@ namespace System.Web.Hosting {
}
}
/// <devdoc>
/// <para>A group of repleacable monitor objects used by ASP.Net subsystems to maintain
/// application health.</para>
/// </devdoc>
public static ApplicationMonitors ApplicationMonitors {
get {
if (_theHostingEnvironment == null)
return null;
return _theHostingEnvironment._applicationMonitors;
}
}
internal static int BusyCount {
get {
if (_theHostingEnvironment == null)
@ -1414,6 +1448,42 @@ namespace System.Web.Hosting {
get { return HttpRuntime.Cache; }
}
internal static NameValueCollection CacheStoreProviderSettings {
get {
if (_cacheProviderSettings == null) {
if (AppDomain.CurrentDomain.IsDefaultAppDomain()) {
Configuration webConfig = WebConfigurationManager.OpenWebConfiguration(null /* root web.config */);
CacheSection cacheConfig = (CacheSection)webConfig.GetSection("system.web/caching/cache");
if (cacheConfig != null && cacheConfig.DefaultProvider != null && !String.IsNullOrWhiteSpace(cacheConfig.DefaultProvider)) {
ProviderSettingsCollection cacheProviders = cacheConfig.Providers;
if (cacheProviders == null || cacheProviders.Count < 1) {
throw new ProviderException(SR.GetString(SR.Def_provider_not_found));
}
ProviderSettings cacheProviderSettings = cacheProviders[cacheConfig.DefaultProvider];
if (cacheProviderSettings == null) {
throw new ProviderException(SR.GetString(SR.Def_provider_not_found));
}
NameValueCollection settings = cacheProviderSettings.Parameters;
settings["name"] = cacheProviderSettings.Name;
settings["type"] = cacheProviderSettings.Type;
_cacheProviderSettings = settings;
}
}
else {
_cacheProviderSettings = AppDomain.CurrentDomain.GetData(".defaultObjectCacheProvider") as NameValueCollection;
}
}
// Return a copy, so the consumer can't mess with our copy of the settings
if (_cacheProviderSettings != null)
return new NameValueCollection(_cacheProviderSettings);
return null;
}
}
// count of all app domain from app manager
internal static int AppDomainsCount {
get {

View File

@ -1 +1 @@
11db9517311df13fd3dac1b168d64148dc88a659
4db80847238960dd859a3a56a9d5530608620e9b

View File

@ -1 +1 @@
ce3d178ea98df8349b79281a9f46ddb56a0a5d73
c89ea82f2a00f973f4b30e96bdb6267a15270780

View File

@ -86,7 +86,7 @@ internal class MapPathBasedVirtualPathProvider: VirtualPathProvider {
// * null means it's not cached
// * true means it's cached and it exists
// * false means it's cached and it doesn't exist
bool? cacheValue = HttpRuntime.CacheInternal[cacheKey] as bool?;
bool? cacheValue = HttpRuntime.Cache.InternalCache.Get(cacheKey) as bool?;
if (cacheValue != null) {
return cacheValue.Value;
}
@ -108,7 +108,7 @@ internal class MapPathBasedVirtualPathProvider: VirtualPathProvider {
if (existingDir != null) {
dep = new CacheDependency(existingDir);
TimeSpan slidingExp = CachedPathData.UrlMetadataSlidingExpiration;
HttpRuntime.CacheInternal.UtcInsert(cacheKey, exists, dep, Cache.NoAbsoluteExpiration, slidingExp);
HttpRuntime.Cache.InternalCache.Insert(cacheKey, exists, new CacheInsertOptions() { Dependencies = dep, SlidingExpiration = slidingExp });
}
return exists;

View File

@ -91,31 +91,20 @@ namespace System.Web.Hosting {
if (memoryCache == null) {
throw new ArgumentNullException("memoryCache");
}
long delta = 0;
lock (_lock) {
if (_cacheInfos != null) {
MemoryCacheInfo info = null;
if (_cacheInfos.TryGetValue(memoryCache, out info)) {
delta = 0 - info.Size;
_cacheInfos.Remove(memoryCache);
}
}
}
if (delta != 0) {
ApplicationManager appManager = HostingEnvironment.GetApplicationManager();
if (appManager != null) {
ExecutionContextUtil.RunInNullExecutionContext(delegate {
appManager.GetUpdatedTotalCacheSize(delta);
});
}
}
}
void IMemoryCacheManager.UpdateCacheSize(long size, MemoryCache memoryCache) {
if (memoryCache == null) {
throw new ArgumentNullException("memoryCache");
}
long delta = 0;
lock (_lock) {
if (_cacheInfos == null) {
_cacheInfos = new Dictionary<MemoryCache, MemoryCacheInfo>();
@ -126,15 +115,8 @@ namespace System.Web.Hosting {
info.Cache = memoryCache;
_cacheInfos[memoryCache] = info;
}
delta = size - info.Size;
info.Size = size;
}
ApplicationManager appManager = HostingEnvironment.GetApplicationManager();
if (appManager != null) {
ExecutionContextUtil.RunInNullExecutionContext(delegate {
appManager.GetUpdatedTotalCacheSize(delta);
});
}
}
internal long TrimCache(int percent) {

View File

@ -78,9 +78,13 @@ namespace System.Web.Hosting {
HttpWriter.ReleaseAllPooledBuffers();
// Trim expired entries from the runtime cache
var cache = HttpRuntime.GetCacheInternal(createIfDoesNotExist: false);
if (cache != null) {
cache.TrimCache(0);
var iCache = HttpRuntime.Cache.GetInternalCache(createIfDoesNotExist: false);
var oCache = HttpRuntime.Cache.GetObjectCache(createIfDoesNotExist: false);
if (iCache != null) {
iCache.Trim(0);
}
if (oCache != null && !oCache.Equals(iCache)) {
oCache.Trim(0);
}
// Trim all pooled HttpApplication instances