|
1 | 1 | #include <host/host.hh>
|
2 | 2 | #include <host/os-bridge.hh>
|
3 | 3 | #include <host/typemap.hh>
|
| 4 | +#include <runtime-base/android-system.hh> |
| 5 | +#include <runtime-base/cpu-arch.hh> |
4 | 6 | #include <runtime-base/internal-pinvokes.hh>
|
5 | 7 | #include <runtime-base/jni-remapping.hh>
|
6 | 8 |
|
@@ -88,3 +90,105 @@ _monodroid_lookup_replacement_method_info (const char *jniSourceType, const char
|
88 | 90 | {
|
89 | 91 | return JniRemapping::lookup_replacement_method_info (jniSourceType, jniMethodName, jniMethodSignature);
|
90 | 92 | }
|
| 93 | + |
| 94 | +managed_timing_sequence* monodroid_timing_start (const char *message) |
| 95 | +{ |
| 96 | + // Technically a reference here is against the idea of shared pointers, but |
| 97 | + // in this instance it's fine since we know we won't be storing the pointer |
| 98 | + // and this way things are slightly faster. |
| 99 | + std::shared_ptr<Timing> const &timing = Host::get_timing (); |
| 100 | + if (!timing) { |
| 101 | + return nullptr; |
| 102 | + } |
| 103 | + |
| 104 | + managed_timing_sequence *ret = timing->get_available_sequence (); |
| 105 | + if (message != nullptr) { |
| 106 | + log_write (LOG_TIMING, LogLevel::Info, message); |
| 107 | + } |
| 108 | + ret->period.mark_start (); |
| 109 | + return ret; |
| 110 | +} |
| 111 | + |
| 112 | +void monodroid_timing_stop (managed_timing_sequence *sequence, const char *message) |
| 113 | +{ |
| 114 | + static constexpr const char DEFAULT_MESSAGE[] = "Managed Timing"; |
| 115 | + if (sequence == nullptr) { |
| 116 | + return; |
| 117 | + } |
| 118 | + |
| 119 | + std::shared_ptr<Timing> const &timing = Host::get_timing (); |
| 120 | + if (!timing) [[unlikely]] { |
| 121 | + return; |
| 122 | + } |
| 123 | + |
| 124 | + sequence->period.mark_end (); |
| 125 | + Timing::info (sequence->period, message == nullptr ? DEFAULT_MESSAGE : message); |
| 126 | + timing->release_sequence (sequence); |
| 127 | +} |
| 128 | + |
| 129 | +void _monodroid_weak_gref_new (jobject curHandle, char curType, jobject newHandle, char newType, const char *threadName, int threadId, const char *from, int from_writable) |
| 130 | +{ |
| 131 | + OSBridge::_monodroid_weak_gref_new (curHandle, curType, newHandle, newType, threadName, threadId, from, from_writable); |
| 132 | +} |
| 133 | + |
| 134 | +int _monodroid_weak_gref_get () |
| 135 | +{ |
| 136 | + return OSBridge::get_gc_weak_gref_count (); |
| 137 | +} |
| 138 | + |
| 139 | +int _monodroid_max_gref_get () |
| 140 | +{ |
| 141 | + return static_cast<int>(AndroidSystem::get_max_gref_count ()); |
| 142 | +} |
| 143 | + |
| 144 | +void _monodroid_weak_gref_delete (jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) |
| 145 | +{ |
| 146 | + OSBridge::_monodroid_weak_gref_delete (handle, type, threadName, threadId, from, from_writable); |
| 147 | +} |
| 148 | + |
| 149 | +void _monodroid_lref_log_new (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) |
| 150 | +{ |
| 151 | + OSBridge::_monodroid_lref_log_new (lrefc, handle, type, threadName, threadId, from, from_writable); |
| 152 | +} |
| 153 | + |
| 154 | +void _monodroid_lref_log_delete (int lrefc, jobject handle, char type, const char *threadName, int threadId, const char *from, int from_writable) |
| 155 | +{ |
| 156 | + OSBridge::_monodroid_lref_log_delete (lrefc, handle, type, threadName, threadId, from, from_writable); |
| 157 | +} |
| 158 | + |
| 159 | +void _monodroid_gc_wait_for_bridge_processing () |
| 160 | +{ |
| 161 | + // mono_gc_wait_for_bridge_processing (); - replace with the new GC bridge call, when we have it |
| 162 | +} |
| 163 | + |
| 164 | +void _monodroid_detect_cpu_and_architecture (uint16_t *built_for_cpu, uint16_t *running_on_cpu, unsigned char *is64bit) |
| 165 | +{ |
| 166 | + abort_if_invalid_pointer_argument (built_for_cpu, "built_for_cpu"); |
| 167 | + abort_if_invalid_pointer_argument (running_on_cpu, "running_on_cpu"); |
| 168 | + abort_if_invalid_pointer_argument (is64bit, "is64bit"); |
| 169 | + |
| 170 | + bool _64bit; |
| 171 | + monodroid_detect_cpu_and_architecture (*built_for_cpu, *running_on_cpu, _64bit); |
| 172 | + *is64bit = _64bit; |
| 173 | +} |
| 174 | + |
| 175 | +void* _monodroid_timezone_get_default_id () |
| 176 | +{ |
| 177 | + JNIEnv *env = OSBridge::ensure_jnienv (); |
| 178 | + jmethodID getDefault = env->GetStaticMethodID (Host::get_java_class_TimeZone (), "getDefault", "()Ljava/util/TimeZone;"); |
| 179 | + jmethodID getID = env->GetMethodID (Host::get_java_class_TimeZone (), "getID", "()Ljava/lang/String;"); |
| 180 | + jobject d = env->CallStaticObjectMethod (Host::get_java_class_TimeZone (), getDefault); |
| 181 | + jstring id = reinterpret_cast<jstring> (env->CallObjectMethod (d, getID)); |
| 182 | + const char *mutf8 = env->GetStringUTFChars (id, nullptr); |
| 183 | + if (mutf8 == nullptr) { |
| 184 | + log_error (LOG_DEFAULT, "Failed to convert Java TimeZone ID to UTF8 (out of memory?)"sv); |
| 185 | + env->DeleteLocalRef (id); |
| 186 | + env->DeleteLocalRef (d); |
| 187 | + return nullptr; |
| 188 | + } |
| 189 | + char *def_id = strdup (mutf8); |
| 190 | + env->ReleaseStringUTFChars (id, mutf8); |
| 191 | + env->DeleteLocalRef (id); |
| 192 | + env->DeleteLocalRef (d); |
| 193 | + return def_id; |
| 194 | +} |
0 commit comments