{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/2314","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/2314/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/2314/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/2314/events","html_url":"https://github.com/dotnet/coreclr/issues/2314","id":121794105,"number":2314,"title":"Assert during MScorlib crossgen","user":{"login":"gkhanna79","id":9451457,"avatar_url":"https://avatars.githubusercontent.com/u/9451457?v=3","gravatar_id":"","url":"https://api.github.com/users/gkhanna79","html_url":"https://github.com/gkhanna79","followers_url":"https://api.github.com/users/gkhanna79/followers","following_url":"https://api.github.com/users/gkhanna79/following{/other_user}","gists_url":"https://api.github.com/users/gkhanna79/gists{/gist_id}","starred_url":"https://api.github.com/users/gkhanna79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkhanna79/subscriptions","organizations_url":"https://api.github.com/users/gkhanna79/orgs","repos_url":"https://api.github.com/users/gkhanna79/repos","events_url":"https://api.github.com/users/gkhanna79/events{/privacy}","received_events_url":"https://api.github.com/users/gkhanna79/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/coreclr/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"ellismg","id":9602953,"avatar_url":"https://avatars.githubusercontent.com/u/9602953?v=3","gravatar_id":"","url":"https://api.github.com/users/ellismg","html_url":"https://github.com/ellismg","followers_url":"https://api.github.com/users/ellismg/followers","following_url":"https://api.github.com/users/ellismg/following{/other_user}","gists_url":"https://api.github.com/users/ellismg/gists{/gist_id}","starred_url":"https://api.github.com/users/ellismg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ellismg/subscriptions","organizations_url":"https://api.github.com/users/ellismg/orgs","repos_url":"https://api.github.com/users/ellismg/repos","events_url":"https://api.github.com/users/ellismg/events{/privacy}","received_events_url":"https://api.github.com/users/ellismg/received_events","type":"User","site_admin":false},"milestone":null,"comments":2,"created_at":"2015-12-11T21:22:56Z","updated_at":"2015-12-11T22:42:54Z","closed_at":null,"body":"I looked into this and it appears to be a regression introduced by the following change from Matt that introduced SecurityCritical SafeSortHandle type that is being referenced in the Transparent CompareInfo.ctor in CompareInfo.Unix.cs. Matt, can you please look into this?\r\n\r\nThanks,\r\nGaurav\r\n\r\n\r\nCommit: 6e2b263b0b1925f1e1d99c652afef460b63c620d[6e2b263]\r\nParents: daa24b15ea\r\nAuthor: Matt Ellis <matell@microsoft.com>\r\nDate: November 19, 2015 at 3:00:20 PM PST\r\nCommit Date: November 20, 2015 at 1:33:34 PM PST\r\n\r\nCache UCollators in CompareInfo\r\n\r\nCreating a UCollator is an expensive operation and we are presently\r\ndoing it on ever collation operation. We can improve this by caching\r\nthe UCollators we use for collation on the CompareInfo object itself.\r\n\r\nThis change introduces a new method GetSortHandle which gives back an\r\nopaque wrapper which can be used in collation operations instead of a\r\nculture name.\r\n\r\nInternally we represent this is a struct holding the two types of\r\nUCollators we care about (if we add additional collators per locale with\r\ndifferent options to handle other types of CompareOption flags, we can\r\ncache these as well). Collation methods can get a `const UCollator*`\r\nreference from the sort handle which is safe to share across\r\nthreads (per the ICU Design Guidelines[1]).\r\n\r\nUnfortunately, tracking the lifetime of the SortHandle itself is not as\r\nstraightfoward as I would like. Right now, we use a SafeHandle to wrap\r\nthe internal handle and rely on the finalizer of the class to clean up\r\nthe native resources. However this means that the following code sample\r\nwill create two finalizable objects:\r\n\r\n```csharp\r\nvar c1 = new CultureInfo(\"en-US\").CompareInfo;\r\nvar c2 = new CultureInfo(\"en-US\").CompareInfo;\r\n```\r\n\r\nIf this ends up being an issue, we could explore an approach where we\r\nkeep a cahce of SortHandles in managed code and pass out references to\r\nthat SortHandle which would let us share a single SortHandle for a given\r\nlocale across more than one CompareInfo object.\r\n\r\nWins are seeing in places where we previously did lots of string\r\ncomparisions in a tight loop (for example: dotnet/corefx#3811) moving\r\nthese operations down to ~6ms per iteration vs ~330ms on my local machine.\r\n\r\n[1]: http://userguide.icu-project.org/design\r\n\r\n\r\n Repro output:\r\n\r\n# ./crossgen ./mscorlib.dll\r\nMicrosoft (R) CoreCLR Native Image Generator - Version 4.5.22220.0\r\nCopyright (c) Microsoft Corporation.  All rights reserved.\r\n \r\n \r\nAssert failure(PID 7323 [0x00001c9b], Thread: 7323 [0x1c9b]): Consistency check failed: Accessibility check failed while compiling platform assembly. Are you missing FriendAccessAllowed attribute? Caller: mscorlib System.Globalization.CompareInfo .ctor Target: SafeSortHandleFAILED: !pContext->GetCallerAssembly()->GetManifestFile()->IsProfileAssembly()\r\n    File: /home/lubo/SVS/src/vm/clsload.cpp Line: 5136\r\n    Image: /home/lubo/coreclr-tests/Windows_NT.x64.Debug/Tests/coreoverlay/crossgen\r\n \r\nAborted (core dumped)\r\nroot@lubo-Virtual-Machine:~/coreclr-tests/Windows_NT.x64.Debug/Tests/coreoverlay#\r\n\r\n@LLITCHEV "},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/164069353","html_url":"https://github.com/dotnet/coreclr/issues/2314#issuecomment-164069353","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/2314","id":164069353,"user":{"login":"gkhanna79","id":9451457,"avatar_url":"https://avatars.githubusercontent.com/u/9451457?v=3","gravatar_id":"","url":"https://api.github.com/users/gkhanna79","html_url":"https://github.com/gkhanna79","followers_url":"https://api.github.com/users/gkhanna79/followers","following_url":"https://api.github.com/users/gkhanna79/following{/other_user}","gists_url":"https://api.github.com/users/gkhanna79/gists{/gist_id}","starred_url":"https://api.github.com/users/gkhanna79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkhanna79/subscriptions","organizations_url":"https://api.github.com/users/gkhanna79/orgs","repos_url":"https://api.github.com/users/gkhanna79/repos","events_url":"https://api.github.com/users/gkhanna79/events{/privacy}","received_events_url":"https://api.github.com/users/gkhanna79/received_events","type":"User","site_admin":false},"created_at":"2015-12-11T22:42:54Z","updated_at":"2015-12-11T22:42:54Z","body":"I believe this will fail at runtime as well as JIT will be asked to generate code to invoke the FieldAccessException helper that will raise the exception when the attempt to access the field takes place. There is no automatic accessibility changes that happen at runtime."}}