Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  golem-tiagent.cc

  Sprache: C
 

/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * 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.
 */


#include "android-base/macros.h"
#include "android-base/logging.h"

#include "jni.h"
#include "jvmti.h"

namespace art {

jvmtiEnv* jvmti_env = nullptr;

void CheckJvmtiError(jvmtiEnv* env, jvmtiError error) {
  if (error != JVMTI_ERROR_NONE) {
    char* error_name;
    jvmtiError name_error = env->GetErrorName(error, &error_name);
    if (name_error != JVMTI_ERROR_NONE) {
      LOG(FATAL) << "Unable to get error name for " << error;
    }
    LOG(FATAL) << "Unexpected error: " << error_name;
  }
}

static void JNICALL VMInitCallback([[maybe_unused]] jvmtiEnv* jenv,
                                   JNIEnv* jni_env,
                                   [[maybe_unused]] jthread thread) {
  // Set a breakpoint on a rare method that we won't expect to be hit.
  // java.lang.Thread.stop is deprecated and not expected to be used.
  jclass cl = jni_env->FindClass("java/lang/Thread");
  if (cl == nullptr) {
    LOG(FATAL) << "Cannot find class java/lang/Thread to set a breakpoint";
  }

  jmethodID method = jni_env->GetMethodID(cl, "stop""()V");
  if (method == nullptr) {
    LOG(FATAL) << "Cannot find method to set a breapoint";
  }

  jlong start = 0;
  jlong end;
  CheckJvmtiError(jvmti_env, jvmti_env->GetMethodLocation(method, &start, &end));
  CheckJvmtiError(jvmti_env, jvmti_env->SetBreakpoint(method, start));
}

extern "C" JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM* vm,
                                               [[maybe_unused]] char* options,
                                               [[maybe_unused]] void* reserved) {
  // Setup jvmti_env
  if (vm->GetEnv(reinterpret_cast<void**>(&jvmti_env), JVMTI_VERSION_1_0) != 0) {
    LOG(ERROR) << "Unable to get jvmti env!";
    return 1;
  }

  // Enable breakpoint capability
  jvmtiCapabilities capabilities;
  memset(&capabilities, 0sizeof(capabilities));
  capabilities.can_generate_breakpoint_events = 1;
  CheckJvmtiError(jvmti_env, jvmti_env->AddCapabilities(&capabilities));

  // Set a callback for VM_INIT phase so we can set a breakpoint. We cannot just
  // set a breakpoint here since vm isn't fully initialized here.
  jvmtiEventCallbacks callbacks;
  memset(&callbacks, 0sizeof(jvmtiEventCallbacks));
  callbacks.VMInit = VMInitCallback;
  CheckJvmtiError(jvmti_env, jvmti_env->SetEventCallbacks(&callbacks, sizeof(callbacks)));
  CheckJvmtiError(jvmti_env,
                  jvmti_env->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_INIT, nullptr));

  return 0;
}

}  // namespace art

Messung V0.5 in Prozent
C=89 H=97 G=93

¤ Dauer der Verarbeitung: 0.13 Sekunden  (vorverarbeitet am  2026-06-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik