move mainThread[H,L], #70319

This commit is contained in:
Johannes Rieken
2019-03-20 14:59:45 +01:00
parent f49b168fa1
commit 6c59d053d5
9 changed files with 70 additions and 58 deletions

View File

@@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtHostContext, IExtHostContext } from '../common/extHost.protocol';
import { Disposable } from 'vs/base/common/lifecycle';
import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { IHeapService } from 'vs/workbench/services/heap/common/heap';
@extHostCustomer
export class MainThreadHeapService extends Disposable {
constructor(
extHostContext: IExtHostContext,
@IHeapService heapService: IHeapService,
) {
super();
const proxy = extHostContext.getProxy(ExtHostContext.ExtHostHeapService);
this._register(heapService.onGarbageCollection((ids) => {
// send to ext host
proxy.$onGarbageCollection(ids);
}));
}
}

View File

@@ -14,7 +14,6 @@ import { Range as EditorRange } from 'vs/editor/common/core/range';
import { ExtHostContext, MainThreadLanguageFeaturesShape, ExtHostLanguageFeaturesShape, MainContext, IExtHostContext, ISerializedLanguageConfiguration, ISerializedRegExp, ISerializedIndentationRule, ISerializedOnEnterRule, LocationDto, WorkspaceSymbolDto, CodeActionDto, reviveWorkspaceEditDto, ISerializedDocumentFilter, DefinitionLinkDto, ISerializedSignatureHelpProviderMetadata, CodeInsetDto, LinkDto, CallHierarchyDto } from '../common/extHost.protocol';
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
import { LanguageConfiguration, IndentationRule, OnEnterRule } from 'vs/editor/common/modes/languageConfiguration';
import { IHeapService } from './mainThreadHeapService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { URI } from 'vs/base/common/uri';
@@ -22,6 +21,7 @@ import { Selection } from 'vs/editor/common/core/selection';
import * as codeInset from 'vs/workbench/contrib/codeinset/common/codeInset';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import * as callh from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { IHeapService } from 'vs/workbench/services/heap/common/heap';
@extHostNamedCustomer(MainContext.MainThreadLanguageFeatures)
export class MainThreadLanguageFeatures implements MainThreadLanguageFeaturesShape {

View File

@@ -29,7 +29,9 @@ import '../browser/mainThreadEditors';
import '../browser/mainThreadErrors';
import '../browser/mainThreadFileSystem';
import '../browser/mainThreadFileSystemEventService';
import '../browser/mainThreadHeapService';
import '../browser/mainThreadLanguages';
import '../browser/mainThreadLanguageFeatures';
import '../browser/mainThreadLogService';
import '../browser/mainThreadMessageService';
import '../browser/mainThreadOutputService';
@@ -49,8 +51,6 @@ import '../browser/mainThreadWorkspace';
import './mainThreadComments';
import './mainThreadConsole';
import './mainThreadExtensionService';
import './mainThreadHeapService';
import './mainThreadLanguageFeatures';
import './mainThreadTask';
import './mainThreadWebview';
import 'vs/workbench/api/node/apiCommands';

View File

@@ -1,118 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtHostContext, ObjectIdentifier, IExtHostContext } from '../common/extHost.protocol';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable } from 'vs/base/common/lifecycle';
import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { GCSignal } from 'gc-signals';
export const IHeapService = createDecorator<IHeapService>('heapService');
export interface IHeapService {
_serviceBrand: any;
readonly onGarbageCollection: Event<number[]>;
/**
* Track gc-collection for the given object
*/
trackObject(obj: ObjectIdentifier | undefined): void;
}
export class HeapService implements IHeapService {
_serviceBrand: any;
private readonly _onGarbageCollection: Emitter<number[]> = new Emitter<number[]>();
public readonly onGarbageCollection: Event<number[]> = this._onGarbageCollection.event;
private _activeSignals = new WeakMap<any, object>();
private _activeIds = new Set<number>();
private _consumeHandle: any;
private _ctor: { new(id: number): GCSignal };
private _ctorInit: Promise<void>;
constructor() {
//
}
dispose() {
clearInterval(this._consumeHandle);
}
trackObject(obj: ObjectIdentifier | undefined | null): void {
if (!obj) {
return;
}
const ident = obj.$ident;
if (typeof ident !== 'number') {
return;
}
if (this._activeIds.has(ident)) {
return;
}
if (this._ctor) {
// track and leave
this._activeIds.add(ident);
this._activeSignals.set(obj, new this._ctor(ident));
} else {
// make sure to load gc-signals, then track and leave
if (!this._ctorInit) {
this._ctorInit = import('gc-signals').then(({ GCSignal, consumeSignals }) => {
this._ctor = GCSignal;
this._consumeHandle = setInterval(() => {
const ids = consumeSignals();
if (ids.length > 0) {
// local book-keeping
for (const id of ids) {
this._activeIds.delete(id);
}
// fire event
this._onGarbageCollection.fire(ids);
}
}, 15 * 1000);
});
}
this._ctorInit.then(() => {
this._activeIds.add(ident);
this._activeSignals.set(obj, new this._ctor(ident));
});
}
}
}
@extHostCustomer
export class MainThreadHeapService {
private readonly _toDispose: IDisposable;
constructor(
extHostContext: IExtHostContext,
@IHeapService heapService: IHeapService,
) {
const proxy = extHostContext.getProxy(ExtHostContext.ExtHostHeapService);
this._toDispose = heapService.onGarbageCollection((ids) => {
// send to ext host
proxy.$onGarbageCollection(ids);
});
}
public dispose(): void {
this._toDispose.dispose();
}
}
registerSingleton(IHeapService, HeapService, true);