private void GetTemporaryStorage( ObjectReader reader, SerializationKinds kind, out ITemporaryStreamStorage storage, out long length, CancellationToken cancellationToken) { if (kind == SerializationKinds.Bits) { storage = _storageService.CreateTemporaryStreamStorage(cancellationToken); using (var stream = SerializableBytes.CreateWritableStream()) { CopyByteArrayToStream(reader, stream, cancellationToken); length = stream.Length; stream.Position = 0; storage.WriteStream(stream, cancellationToken); } return; } if (kind == SerializationKinds.MemoryMapFile) { var service2 = _storageService as ITemporaryStorageService2; Contract.ThrowIfNull(service2); var name = reader.ReadString(); var size = reader.ReadInt64(); storage = service2.AttachTemporaryStreamStorage(name, size, cancellationToken); length = size; return; } throw ExceptionUtilities.UnexpectedValue(kind); }
private bool ReparseCommandLineIfChanged_NoLock(string commandLine) { var checksum = Checksum.Create(commandLine); if (_commandLineChecksum == checksum) { return(false); } _commandLineChecksum = checksum; // Dispose the existing stored command-line and then persist the new one so we can // recover it later. Only bother persisting things if we have a non-empty string. _commandLineStorage?.Dispose(); _commandLineStorage = null; if (commandLine.Length > 0) { _commandLineStorage = _temporaryStorageService.CreateTemporaryStreamStorage(); _commandLineStorage.WriteString(commandLine); } ReparseCommandLine_NoLock(commandLine); return(true); }
public static MetadataOnlyImage Create(ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return new MetadataOnlyImage(storage, compilation.AssemblyName); } } } return Empty; }
public static MetadataOnlyImage Create(ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } } } return(Empty); }
private bool ReparseCommandLineIfChanged_NoLock(ImmutableArray <string> arguments) { var checksum = Checksum.Create(arguments); if (_commandLineChecksum == checksum) { return(false); } _commandLineChecksum = checksum; // Dispose the existing stored command-line and then persist the new one so we can // recover it later. Only bother persisting things if we have a non-empty string. _commandLineStorage?.Dispose(); _commandLineStorage = null; if (!arguments.IsEmpty) { _commandLineStorage = _temporaryStorageService.CreateTemporaryStreamStorage(); _commandLineStorage.WriteAllLines(arguments); } ReparseCommandLine_NoLock(arguments); return(true); }
public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } // log emit failures so that we can improve most common cases Logger.Log(FunctionId.MetadataOnlyImage_EmitFailure, KeyValueLogMessage.Create(m => { // log errors in the format of // CS0001:1;CS002:10;... var groups = emitResult.Diagnostics.GroupBy(d => d.Id).Select(g => $"{g.Key}:{g.Count()}"); m["Errors"] = string.Join(";", groups); })); } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return(Empty); }
public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return(new MetadataOnlyImage(storage, compilation.AssemblyName)); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return(Empty); }
public static MetadataOnlyImage Create(Workspace workspace, ITemporaryStorageService service, Compilation compilation, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); try { workspace.LogTestMessage($"Beginning to create a skeleton assembly for {compilation.AssemblyName}..."); using (Logger.LogBlock(FunctionId.Workspace_SkeletonAssembly_EmitMetadataOnlyImage, cancellationToken)) { // TODO: make it to use SerializableBytes.WritableStream rather than MemoryStream so that // we don't allocate anything for skeleton assembly. using (var stream = SerializableBytes.CreateWritableStream()) { // note: cloning compilation so we don't retain all the generated symbols after its emitted. // * REVIEW * is cloning clone p2p reference compilation as well? var emitResult = compilation.Clone().Emit(stream, options: s_emitOptions, cancellationToken: cancellationToken); if (emitResult.Success) { workspace.LogTestMessage($"Successfully emitted a skeleton assembly for {compilation.AssemblyName}"); var storage = service.CreateTemporaryStreamStorage(cancellationToken); stream.Position = 0; storage.WriteStream(stream, cancellationToken); return new MetadataOnlyImage(storage, compilation.AssemblyName); } else { workspace.LogTestMessage($"Failed to create a skeleton assembly for {compilation.AssemblyName}:"); foreach (var diagnostic in emitResult.Diagnostics) { workspace.LogTestMessage(" " + diagnostic.GetMessage()); } } } } } finally { workspace.LogTestMessage($"Done trying to create a skeleton assembly for {compilation.AssemblyName}"); } return Empty; }
private void GetStorageInfoFromTemporaryStorage(FileKey moduleFileKey, out ITemporaryStreamStorage storage, out Stream stream, out IntPtr pImage) { int size; using (var copyStream = SerializableBytes.CreateWritableStream()) { // open a file and let it go as soon as possible using (var fileStream = FileUtilities.OpenRead(moduleFileKey.FullPath)) { var headers = new PEHeaders(fileStream); var offset = headers.MetadataStartOffset; size = headers.MetadataSize; // given metadata contains no metadata info. // throw bad image format exception so that we can show right diagnostic to user. if (size <= 0) { throw new BadImageFormatException(); } StreamCopy(fileStream, copyStream, offset, size); } // copy over the data to temp storage and let pooled stream go storage = _temporaryStorageService.CreateTemporaryStreamStorage(CancellationToken.None); copyStream.Position = 0; storage.WriteStream(copyStream); } // get stream that owns direct access memory stream = storage.ReadStream(CancellationToken.None); // stream size must be same as what metadata reader said the size should be. Contract.ThrowIfFalse(stream.Length == size); // under VS host, direct access should be supported var directAccess = (ISupportDirectMemoryAccess)stream; pImage = directAccess.GetPointer(); }