MCPcopy Create free account
hub / github.com/Snapchat/Valdi / make

Method make

valdi_core/src/valdi_core/jni/JavaFunctionTrampolineHelper.cpp:94–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94JavaFunctionTrampolineHelper* JavaFunctionTrampolineHelper::make() {
95 auto cls = JavaClass::resolveOrAbort(JavaEnv(), "com/snap/valdi/callable/ValdiFunctionTrampoline");
96
97 auto getFunctionClassesMethod = cls.getStaticMethod(
98 "getFunctionClasses", Valdi::ValueSchema::array(Valdi::ValueSchema::untyped()), nullptr, 0, false);
99
100 auto functionClasses = getFunctionClassesMethod.call(reinterpret_cast<jobject>(cls.getClass()), 0, nullptr);
101
102 JavaObjectArray array(functionClasses.getObjectArray());
103
104 auto size = array.size();
105 SC_ASSERT(size % 5 == 0);
106
107 Valdi::InlineContainerAllocator<JavaFunctionTrampolineHelper, JavaFunctionTrampolineHelperEntry> allocator;
108
109 auto entriesCount = size / 5;
110 auto* trampolineHelper = allocator.allocateUnmanaged(entriesCount, std::move(cls), entriesCount);
111
112 size_t entryIndex = 0;
113
114 for (size_t i = 0; i < size;) {
115 auto functionClassName = array.getObject(i++);
116 auto functionClass = array.getObject(i++);
117 auto bridgeFunctionClass = array.getObject(i++);
118 auto invokeMethod = array.getObject(i++);
119 auto constructorMethod = array.getObject(i++);
120
121 auto invoker = AnyJavaMethod::fromReflectedMethod(invokeMethod.get(), false, JavaValueType::Object);
122 auto constructor = AnyJavaMethod::fromReflectedMethod(constructorMethod.get(), false, JavaValueType::Object);
123
124 auto& entry = allocator.getContainerStartPtr(trampolineHelper)[entryIndex];
125 entry.functionClassName = toInternedString(JavaEnv(), reinterpret_cast<jstring>(functionClassName.get()));
126 entry.functionClass = JavaClass(JavaEnv(), reinterpret_cast<jclass>(functionClass.get()));
127 entry.bridgeFunctionClass = JavaClass(JavaEnv(), reinterpret_cast<jclass>(bridgeFunctionClass.get()));
128 entry.invoker = invoker;
129 entry.bridgeFunctionConstructor.setMethodId(constructor.getMethodId());
130
131 entryIndex++;
132 }
133
134 return trampolineHelper;
135}
136
137} // namespace ValdiAndroid

Callers

nothing calls this directly

Calls 14

toInternedStringFunction · 0.85
getObjectArrayMethod · 0.80
allocateUnmanagedMethod · 0.80
setMethodIdMethod · 0.80
getMethodIdMethod · 0.80
JavaEnvClass · 0.70
JavaClassClass · 0.70
callMethod · 0.65
getObjectMethod · 0.65
getMethod · 0.65
getStaticMethodMethod · 0.45
getClassMethod · 0.45

Tested by

no test coverage detected