Skip to content

Conversation

@dellis1972
Copy link
Contributor

In commit 75023bd we noticed an issue the
value of MonoPackageManager_Resouces.ApiPackageName was
"" even after it was replaced at built time with a new
.class file which contained an actual value.

The fix in that PR was to make the temp file in java-runtime
have a value of null rather than "". This made thing work
but we didn't know WHY.

After some more investigation it turns out that the value
was being inlined by the java compiler.

public static java.lang.String getApiPackageName();
    descriptor: ()Ljava/lang/String;
    Code:
       0: ldc           #48                 // String
       2: areturn

The code above is pointing to a string in the Constants table.
What we were expecting was that the statick method would be
called in the file generated by the build system. Making
the temp file have a null rather than "" resulted in the
following code

public static java.lang.String getApiPackageName();
    descriptor: ()Ljava/lang/String;
    Code:
       0: getstatic     #47                 // Field mono/MonoPackageManager_Resources.ApiPackageName:Ljava/lang/String;
       3: areturn

This is why changing to null worked. It prevented the compiler
from inlining the value.

This commit removes the final keyword from the MonoPackageManager_Resources
class fields to make sure that they never get inlined.

In commit 75023bd we noticed an issue the
value of `MonoPackageManager_Resouces.ApiPackageName` was
`""` even after it was replaced at built time with a new
`.class` file which contained an actual value.

The fix in that PR was to make the temp file in java-runtime
have a value of `null` rather than `""`. This made thing work
but we didn't know WHY.

After some more investigation it turns out that the value
was being inlined by the java compiler.

	public static java.lang.String getApiPackageName();
	    descriptor: ()Ljava/lang/String;
	    Code:
	       0: ldc           #48                 // String
	       2: areturn

The code above is pointing to a string in the Constants table.
What we were expecting was that the statick method would be
called in the file generated by the build system. Making
the temp file have a `null` rather than `""` resulted in the
following code

	public static java.lang.String getApiPackageName();
	    descriptor: ()Ljava/lang/String;
	    Code:
	       0: getstatic     #47                 // Field mono/MonoPackageManager_Resources.ApiPackageName:Ljava/lang/String;
	       3: areturn

This is why changing to `null` worked. It prevented the compiler
from inlining the value.

This commit removes the `final` keyword from the `MonoPackageManager_Resources`
class fields to make sure that they never get inlined.
@jonathanpeppers
Copy link
Member

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can ignore the test failure:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(114,5): Unable to load the service index for source https://msazure.pkgs.visualstudio.com/_packaging/Dev/nuget/v3/index.json.
  Response status code does not indicate success: 401 (Unauthorized). [E:\A\_work\910\s\bin\TestRelease\temp\BuildBasicApplicationFSharp\UnnamedProject.fsproj]

@jonathanpeppers
Copy link
Member

It may be worth linking to: https://stackoverflow.com/questions/3524150/is-it-possible-to-disable-javacs-inlining-of-static-final-variables

Apparently there are not any good ways to prevent the inlining here... There are some other options on here, though.

@jonpryor jonpryor merged commit 6ca943e into dotnet:master Mar 26, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants