Skip to content

Commit

Permalink
Dealloc JNI implementation experiment
Browse files Browse the repository at this point in the history
Summary:
@public

Remove ability to configure Yoga to run with/without JNI fast calls on dalvik / art.
This switches to always run with fast calls.

Reviewed By: astreet

Differential Revision: D13144652

fbshipit-source-id: 091aab0cd1290d46346323d3e26a11dd0bb17187
  • Loading branch information
davidaurelio authored and facebook-github-bot committed Nov 22, 2018
1 parent f8ff6bd commit 64d162e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 156 deletions.
3 changes: 2 additions & 1 deletion ReactAndroid/src/main/java/com/facebook/yoga/YogaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;

@DoNotStrip
public class YogaConfig {

public static int SPACING_TYPE = 1;

static {
YogaJNI.init();
SoLoader.loadLibrary("yoga");
}

long mNativePointer;
Expand Down
32 changes: 0 additions & 32 deletions ReactAndroid/src/main/java/com/facebook/yoga/YogaJNI.java

This file was deleted.

3 changes: 2 additions & 1 deletion ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
Expand All @@ -16,7 +17,7 @@
public class YogaNode implements Cloneable {

static {
YogaJNI.init();
SoLoader.loadLibrary("yoga");
}

/**
Expand Down
224 changes: 102 additions & 122 deletions ReactAndroid/src/main/jni/first-party/yogajni/jni/YGJNI.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) Facebook, Inc.
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE
* file in the root directory of this source tree.
Expand Down Expand Up @@ -658,132 +658,112 @@ jint jni_YGNodeGetInstanceCount() {
}

#define YGMakeNativeMethod(name) makeNativeMethod(#name, name)
#define YGRealMakeCriticalNativeMethod(name) \
makeCriticalNativeMethod(#name, name)
#define YGWrapCriticalNativeMethodForRegularCall(name) \
makeNativeMethod( \
#name, \
::facebook::jni::detail::CriticalMethod<decltype(&name)>::call<&name>)

#define YGRegisterNatives(YGMakeCriticalNativeMethod) \
registerNatives( \
"com/facebook/yoga/YogaNode", \
{ \
YGMakeNativeMethod(jni_YGNodeNew), \
YGMakeNativeMethod(jni_YGNodeNewWithConfig), \
YGMakeCriticalNativeMethod(jni_YGNodeFree), \
YGMakeCriticalNativeMethod(jni_YGNodeReset), \
YGMakeCriticalNativeMethod(jni_YGNodeClearChildren), \
YGMakeCriticalNativeMethod(jni_YGNodeInsertChild), \
YGMakeCriticalNativeMethod(jni_YGNodeInsertSharedChild), \
YGMakeCriticalNativeMethod(jni_YGNodeRemoveChild), \
YGMakeCriticalNativeMethod(jni_YGNodeSetIsReferenceBaseline), \
YGMakeCriticalNativeMethod(jni_YGNodeIsReferenceBaseline), \
YGMakeNativeMethod(jni_YGNodeCalculateLayout), \
YGMakeCriticalNativeMethod(jni_YGNodeMarkDirty), \
YGMakeCriticalNativeMethod( \
jni_YGNodeMarkDirtyAndPropogateToDescendants), \
YGMakeCriticalNativeMethod(jni_YGNodeIsDirty), \
YGMakeCriticalNativeMethod(jni_YGNodeSetHasMeasureFunc), \
YGMakeCriticalNativeMethod(jni_YGNodeSetHasBaselineFunc), \
YGMakeCriticalNativeMethod(jni_YGNodeCopyStyle), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDirection), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDirection), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexDirection), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexDirection), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetJustifyContent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetJustifyContent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignItems), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignItems), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignSelf), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignSelf), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignContent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignContent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPositionType), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionType), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexWrap), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetOverflow), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetOverflow), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDisplay), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDisplay), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlex), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexGrow), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexGrow), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexShrink), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexShrink), \
YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasis), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisAuto), \
YGMakeNativeMethod(jni_YGNodeStyleGetMargin), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMargin), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginAuto), \
YGMakeNativeMethod(jni_YGNodeStyleGetPadding), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPadding), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPaddingPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetBorder), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetBorder), \
YGMakeNativeMethod(jni_YGNodeStyleGetPosition), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPosition), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionPercent), \
YGMakeNativeMethod(jni_YGNodeStyleGetWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthAuto), \
YGMakeNativeMethod(jni_YGNodeStyleGetHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightAuto), \
YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidthPercent), \
YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeightPercent), \
YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidth), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidthPercent), \
YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeight), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeightPercent), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAspectRatio), \
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio), \
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount), \
YGMakeCriticalNativeMethod(jni_YGNodePrint), \
YGMakeNativeMethod(jni_YGNodeClone), \
YGMakeCriticalNativeMethod(jni_YGNodeSetOwner), \
}); \
registerNatives( \
"com/facebook/yoga/YogaConfig", \
{ \
YGMakeNativeMethod(jni_YGConfigNew), \
YGMakeNativeMethod(jni_YGConfigFree), \
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled), \
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults), \
YGMakeNativeMethod(jni_YGConfigSetPrintTreeFlag), \
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor), \
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour), \
YGMakeNativeMethod(jni_YGConfigSetLogger), \
YGMakeNativeMethod(jni_YGConfigSetHasCloneNodeFunc), \
YGMakeNativeMethod( \
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour), \
});

void jni_bindNativeMethods(alias_ref<jclass>, jboolean useFastCall) {
if (useFastCall) {
YGRegisterNatives(YGRealMakeCriticalNativeMethod);
} else {
YGRegisterNatives(YGWrapCriticalNativeMethodForRegularCall);
}
}
#define YGMakeCriticalNativeMethod(name) makeCriticalNativeMethod(#name, name)

jint JNI_OnLoad(JavaVM* vm, void*) {
return initialize(vm, [] {
registerNatives(
"com/facebook/yoga/YogaJNI",
"com/facebook/yoga/YogaNode",
{
YGMakeNativeMethod(jni_YGNodeNew),
YGMakeNativeMethod(jni_YGNodeNewWithConfig),
YGMakeCriticalNativeMethod(jni_YGNodeFree),
YGMakeCriticalNativeMethod(jni_YGNodeReset),
YGMakeCriticalNativeMethod(jni_YGNodeClearChildren),
YGMakeCriticalNativeMethod(jni_YGNodeInsertChild),
YGMakeCriticalNativeMethod(jni_YGNodeInsertSharedChild),
YGMakeCriticalNativeMethod(jni_YGNodeRemoveChild),
YGMakeCriticalNativeMethod(jni_YGNodeSetIsReferenceBaseline),
YGMakeCriticalNativeMethod(jni_YGNodeIsReferenceBaseline),
YGMakeNativeMethod(jni_YGNodeCalculateLayout),
YGMakeCriticalNativeMethod(jni_YGNodeMarkDirty),
YGMakeCriticalNativeMethod(
jni_YGNodeMarkDirtyAndPropogateToDescendants),
YGMakeCriticalNativeMethod(jni_YGNodeIsDirty),
YGMakeCriticalNativeMethod(jni_YGNodeSetHasMeasureFunc),
YGMakeCriticalNativeMethod(jni_YGNodeSetHasBaselineFunc),
YGMakeCriticalNativeMethod(jni_YGNodeCopyStyle),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexDirection),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetJustifyContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetJustifyContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignItems),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignItems),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignSelf),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignSelf),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAlignContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAlignContent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetPositionType),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionType),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexWrap),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetOverflow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetOverflow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetDisplay),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetDisplay),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlex),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexGrow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexGrow),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetFlexShrink),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexShrink),
YGMakeNativeMethod(jni_YGNodeStyleGetFlexBasis),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasis),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetFlexBasisAuto),
YGMakeNativeMethod(jni_YGNodeStyleGetMargin),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMargin),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMarginAuto),
YGMakeNativeMethod(jni_YGNodeStyleGetPadding),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPadding),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPaddingPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetBorder),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetBorder),
YGMakeNativeMethod(jni_YGNodeStyleGetPosition),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPosition),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetPositionPercent),
YGMakeNativeMethod(jni_YGNodeStyleGetWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetWidthAuto),
YGMakeNativeMethod(jni_YGNodeStyleGetHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetHeightAuto),
YGMakeNativeMethod(jni_YGNodeStyleGetMinWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinWidthPercent),
YGMakeNativeMethod(jni_YGNodeStyleGetMinHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMinHeightPercent),
YGMakeNativeMethod(jni_YGNodeStyleGetMaxWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidth),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxWidthPercent),
YGMakeNativeMethod(jni_YGNodeStyleGetMaxHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeight),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetMaxHeightPercent),
YGMakeCriticalNativeMethod(jni_YGNodeStyleGetAspectRatio),
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
YGMakeCriticalNativeMethod(jni_YGNodePrint),
YGMakeNativeMethod(jni_YGNodeClone),
YGMakeCriticalNativeMethod(jni_YGNodeSetOwner),
});
registerNatives(
"com/facebook/yoga/YogaConfig",
{
YGMakeNativeMethod(jni_bindNativeMethods),
YGMakeNativeMethod(jni_YGConfigNew),
YGMakeNativeMethod(jni_YGConfigFree),
YGMakeNativeMethod(jni_YGConfigSetExperimentalFeatureEnabled),
YGMakeNativeMethod(jni_YGConfigSetUseWebDefaults),
YGMakeNativeMethod(jni_YGConfigSetPrintTreeFlag),
YGMakeNativeMethod(jni_YGConfigSetPointScaleFactor),
YGMakeNativeMethod(jni_YGConfigSetUseLegacyStretchBehaviour),
YGMakeNativeMethod(jni_YGConfigSetLogger),
YGMakeNativeMethod(jni_YGConfigSetHasCloneNodeFunc),
YGMakeNativeMethod(
jni_YGConfigSetShouldDiffLayoutWithoutLegacyStretchBehaviour),
});
});
}

0 comments on commit 64d162e

Please sign in to comment.