Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsatisfiedLinkError: cannot find native jdk.internal.reflect.Reflection.getClassAccessFlags #106

Closed
gayanW opened this issue Jul 20, 2018 · 5 comments

Comments

@gayanW
Copy link
Collaborator

gayanW commented Jul 20, 2018

Runtime error "java.lang.UnsatisfiedLinkError: cannot find native jdk.internal.reflect.Reflection.getClassAccessFlags" when running CountDownLatchTest

[junit] java.lang.UnsatisfiedLinkError: cannot find native jdk.internal.reflect.Reflection.getClassAccessFlags
[junit]     at jdk.internal.reflect.Reflection.getClassAccessFlags(gov.nasa.jpf.vm.JPF_jdk_internal_reflect_Reflection)
[junit]     at sun.invoke.util.VerifyAccess.getClassModifiers(VerifyAccess.java:156)
[junit]     at sun.invoke.util.VerifyAccess.isClassAccessible(VerifyAccess.java:177)
[junit]     at java.lang.invoke.MethodHandles$Lookup.checkSymbolicClass(MethodHandles.java:2047)
[junit]     at java.lang.invoke.MethodHandles$Lookup.resolveOrFail(MethodHandles.java:2020)
[junit]     at java.lang.invoke.MethodHandles$Lookup.findVarHandle(MethodHandles.java:1516)
[junit]     at java.util.concurrent.locks.AbstractQueuedSynchronizer.<clinit>(AbstractQueuedSynchronizer.java:2301)
[junit]     at java.util.concurrent.CountDownLatch.<init>(CountDownLatch.java:201)
[junit]     at gov.nasa.jpf.test.java.concurrent.CountDownLatchTest.testCountDown(CountDownLatchTest.java:43)

The above error follows after the PR #104

@cyrille-artho
Copy link
Member

As far as I can tell, JPF currently does not search inner classes (perhaps it should), so we can probably get away with delegating this to Class.getModifiers().
The native peer for that method is public int getModifiers____I (MJIEnv env, int clsRef).

@gayanW
Copy link
Collaborator Author

gayanW commented Jul 24, 2018

When you say 'search' did you mean the resolving of the classes?. If so, I could confirm that it resolves not just the superclasses and interfaces of a requested class but also its static inner classes (eg: java.lang.String$CaseInsensitiveComparator), and nested interfaces (eg: java.lang.Thread$UncaughtExceptionHandler)

@gayanW
Copy link
Collaborator Author

gayanW commented Jul 24, 2018

Reflection#getClassAccessFlags(java.lang.Class) is only called about twice for entire test units. I think it is safe to say that the native int getClassAccessFlags(Class<?> c) is never called with an inner class as the argument c, while running the tests.

I've tried the following implementation:

  /**
   * NativePeer method for {@link jdk.internal.reflect.Reflection#getClassAccessFlags(java.lang.Class)}
   */
  @MJI
  public static int getClassAccessFlags__Ljava_lang_Class_2__I(MJIEnv env, int clsObjRef, int cRef) {
    try {
      ClassInfo classInfo = env.getClassInfo(cRef);
      Class<?> c = Class.forName(classInfo.getName());
      return c.getModifiers();

    } catch (ClassNotFoundException e) {
      return MJIEnv.NULL;
    }
  }

But I'm not quite sure about the following code snippet:

  ClassInfo classInfo = env.getClassInfo(cRef);
  Class<?> c = Class.forName(classInfo.getName());

Is this the correct approach to retrieve a Class object associated with given class reference (int cRef)?

@cyrille-artho
Copy link
Member

Yes, I meant the mechanism of searching super classes/interfaces for methods that cannot be found in the current class.

@cyrille-artho
Copy link
Member

ClassInfo classInfo = env.getClassInfo(cRef); Class<?> c = Class.forName(classInfo.getName());

Thanks for asking. This would get the information about class ClassInfo, not the class that you're actually looking for. Instead, return the modifiers from classInfo itself:
return classInfo.getModifiers();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants