// Copyright 2017 The Promagent Authors
//
// 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 io.promagent.agent;

import java.lang.instrument.Instrumentation;

/**
 * We want as little dependencies as possible on the system class loader,
 * so the agent just delegates to the real agent which is loaded using our own class loader.
 */
public class Promagent {
    public static void premain(String agentArgs, Instrumentation inst) throws Exception {
        Object realAgent = ClassLoaderCache.getInstance().currentClassLoader().loadClass("io.promagent.internal.Promagent").newInstance();
        realAgent.getClass().getMethod("premain", String.class, Instrumentation.class).invoke(realAgent, agentArgs, inst);
    }
}

@@ -756,37 +756,11 @@
 he a
-gent just delegates to the re
+ctu
 al a
@@ -768,14 +768,8 @@
 ent 
-which 
 is l
@@ -778,17 +778,14 @@
 ded 
-using our
+in its
  own
@@ -797,16 +797,47 @@
 s loader
+ and this agent delegates to it
 .%0A */%0Apu
@@ -961,24 +961,36 @@
     
-Object realAgent
+ClassLoader agentClassLoader
  = C
@@ -1039,16 +1039,64 @@
 Loader()
+;%0A        Class%3C?%3E agentClass = agentClassLoader
 .loadCla
@@ -1136,52 +1136,28 @@
 nt%22)
-.newInstance();%0A        realAgent.ge
+;%0A        agen
 tClass
-()
 .get
@@ -1222,17 +1222,12 @@
 oke(
-realAgent
+null
 , ag

remove unnecessary object creation