<commit_before>/*
 * Copyright 2006 <NAME>
 * 
 * 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 net.sf.profiler4j.agent;

import static net.sf.profiler4j.agent.AgentConstants.VERSION;
import static net.sf.profiler4j.agent.Log.print;
import static net.sf.profiler4j.agent.ThreadProfiler.globalLock;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Class responsible for the intialization of the agent.
 * 
 * @author <NAME>
 */
public class Agent {

    static Transformer t;
    static Instrumentation inst;

    static final Object waitConnectionLock = new Object();
    static Server server;
    static Config config;

    static RuntimeMXBean rtbean = ManagementFactory.getRuntimeMXBean();
    static List<GarbageCollectorMXBean> gcbeans = ManagementFactory
        .getGarbageCollectorMXBeans();
    static MemoryMXBean membean = ManagementFactory.getMemoryMXBean();
    static ThreadMXBean threadbean = ManagementFactory.getThreadMXBean();

    volatile static boolean beingShutdown;

    /**
     * Set with the name of all currently transformed classes. Notice that his set should
     * be used only for informative purposes as it may be imprecise.
     * <p>
     * It is interesting to see that the effective number of modified classes may be
     * greater than <tt>modifiedClasses.size()</tt>. This happens when more than one
     * class loader loads a class with same name.
     */
    static final Set<String> modifiedClassNames = new HashSet<String>();
    static int modifiedClassCount;

    /**
     * Premain method called before the target application is initialized.
     * 
     * @param args command line argument passed via <code>-javaagent</code>
     * @param inst instance of the instrumentation service
     */
    public static void premain(String args, Instrumentation inst) {

        print(0, "+---------------------------------------------------+");
        print(0, "| Profiler4j Agent " + String.format("%-33s", VERSION) + "|");
        print(0, "| Copyright 2006 <NAME>                |");
        print(0, "| See LICENSE-2.0.txt details                       |");
        print(0, "+---------------------------------------------------+");

        doPreInitialization(inst);

        try {
            config = new Config(args);
            if (config.isEnabled()) {

                Log.setVerbosity(config.getVerbosity());

                server = new Server(config);
                server.start();
                try {
                    // warm-up time (sometimes needed)
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // ignore
                }

                t = new Transformer(config);

                BytecodeTransformer.enabled = true;
                inst.addTransformer(t);

                Agent.inst = inst;

                Runtime.getRuntime().addShutdownHook(new Thread() {
                    @Override
                    public void run() {
                        beingShutdown = true;<commit_msg>Changed the copyright info in the agent's splash console output, because I missed it before and don't know if I may omit it.<commit_after>/*
 * Copyright 2006 <NAME>
 * 
 * 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 net.sf.profiler4j.agent;

import static net.sf.profiler4j.agent.AgentConstants.VERSION;
import static net.sf.profiler4j.agent.Log.print;
import static net.sf.profiler4j.agent.ThreadProfiler.globalLock;

import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.RuntimeMXBean;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Class responsible for the intialization of the agent.
 * 
 * @author <NAME>
 */
public class Agent {

    static Transformer t;
    static Instrumentation inst;

    static final Object waitConnectionLock = new Object();
    static Server server;
    static Config config;

    static RuntimeMXBean rtbean = ManagementFactory.getRuntimeMXBean();
    static List<GarbageCollectorMXBean> gcbeans = ManagementFactory
        .getGarbageCollectorMXBeans();
    static MemoryMXBean membean = ManagementFactory.getMemoryMXBean();
    static ThreadMXBean threadbean = ManagementFactory.getThreadMXBean();

    volatile static boolean beingShutdown;

    /**
     * Set with the name of all currently transformed classes. Notice that his set should
     * be used only for informative purposes as it may be imprecise.
     * <p>
     * It is interesting to see that the effective number of modified classes may be
     * greater than <tt>modifiedClasses.size()</tt>. This happens when more than one
     * class loader loads a class with same name.
     */
    static final Set<String> modifiedClassNames = new HashSet<String>();
    static int modifiedClassCount;

    /**
     * Premain method called before the target application is initialized.
     * 
     * @param args command line argument passed via <code>-javaagent</code>
     * @param inst instance of the instrumentation service
     */
    public static void premain(String args, Instrumentation inst) {

        print(0, "+---------------------------------------------------+");
        print(0, "| Profiler4j Agent " + String.format("%-33s", VERSION) + "|");
        print(0, "| Copyright 2006 <NAME>                |");
        print(0, "| Copyright 2009 <NAME>                       |");
        print(0, "| See LICENSE-2.0.txt details                       |");
        print(0, "+---------------------------------------------------+");

        doPreInitialization(inst);

        try {
            config = new Config(args);
            if (config.isEnabled()) {

                Log.setVerbosity(config.getVerbosity());

                server = new Server(config);
                server.start();
                try {
                    // warm-up time (sometimes needed)
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    // ignore
                }

                t = new Transformer(config);

                BytecodeTransformer.enabled = true;
                inst.addTransformer(t);

                Agent.inst = inst;

                Runtime.getRuntime().addShutdownHook(new Thread() {
                    @Override
                    public void run() {
                        beingShutdown = true;
{'fraction_non_alphanumeric': 0.11169678714859438, 'fraction_numerical': 0.007906626506024096, 'mean_word_length': 2.3259599332220366, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3510055', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1954, 'n_words': 659}