Skip to content

Commit

Permalink
Keep all the HybridData's members
Browse files Browse the repository at this point in the history
Summary: It's safer to keep all the members in the `HybridData` and `HybridData$Destructor` instead of annotating `DoNotStrip` on all the members.

Reviewed By: aandreyeu

Differential Revision: D46769581

fbshipit-source-id: 9ee17e490e65316c6f8395758d85bc9a8c82f978
  • Loading branch information
simpleton authored and facebook-github-bot committed Jun 19, 2023
1 parent 83cc597 commit d08a84e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 5 additions & 5 deletions java/com/facebook/jni/HybridData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.facebook.jni;

import com.facebook.jni.annotations.DoNotStrip;
import com.facebook.jni.annotations.DoNotStripAny;
import com.facebook.soloader.nativeloader.NativeLoader;

/**
Expand All @@ -27,14 +27,14 @@
* <p>{@link #resetNative} deletes the corresponding native object synchronously on whatever thread
* the method is called on. Otherwise, deletion will occur on the {@link DestructorThread} thread.
*/
@DoNotStrip
@DoNotStripAny
public class HybridData {

static {
NativeLoader.loadLibrary("fbjni");
}

@DoNotStrip private Destructor mDestructor = new Destructor(this);
private final Destructor mDestructor = new Destructor(this);

/**
* To explicitly delete the instance, call resetNative(). If the C++ instance is referenced after
Expand Down Expand Up @@ -64,11 +64,11 @@ public boolean isValid() {
return mDestructor.mNativePointer != 0;
}

@DoNotStrip
@DoNotStripAny
public static class Destructor extends DestructorThread.Destructor {

// Private C++ instance
@DoNotStrip private volatile long mNativePointer;
private volatile long mNativePointer;

Destructor(Object referent) {
super(referent);
Expand Down
33 changes: 33 additions & 0 deletions java/com/facebook/jni/annotations/DoNotStripAny.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.facebook.jni.annotations;

import static java.lang.annotation.RetentionPolicy.CLASS;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Add this annotation to a class to instruct Proguard to not strip it or any of its fields or
* methods out.
*
* <p>This is useful for methods called via reflection that could appear as unused to Proguard.
*/
@Target({ElementType.TYPE})
@Retention(CLASS)
public @interface DoNotStripAny {}

0 comments on commit d08a84e

Please sign in to comment.