@Override
   public byte[] transform(final ClassLoader loader, final String className,
         final Class<?> classBeingRedefined,
         final ProtectionDomain protectionDomain, final byte[] classfileBuffer)
         throws IllegalClassFormatException {

      if (LOGGER.isLoggable(Level.FINEST)) {
         final String name = classBeingRedefined == null ? null
               : classBeingRedefined.getName();
         final Class<? extends ClassLoader> loaderClass = loader == null ? null
               : loader.getClass();
         final int size = classfileBuffer == null ? -1 : classfileBuffer.length;
         LOGGER.finest(String.format(
               "transform class: %s, loader: %s, redefined: %s size: %s",
               className, loaderClass, name, size));
      }

      final long t0 = System.nanoTime();
      final byte[] result;

      callCounter.incrementAndGet();
      if (mustRedefine(loader, className)) {
         // Class is interesting
         final ClassKey key = new ClassKey(loader, className);
         if (classBeingRedefined == null) {
            // Class is being loaded, so we cache its bytecode
            originalDefinitions.putIfAbsent(key, classfileBuffer);
         } else {
            // Class is being redefined. We should have it in our cache.
            assert originalDefinitions.contains(key) : className;
         }

         if (isActive()) {
            result = enhance(classfileBuffer);
         } else {
            // Either load the class or restores it
            result = originalDefinitions.get(key);
         }

         instrumentedClassesCounter.incrementAndGet();
      } else {
         result = null;
      }

      estimatedOverHead.addAndGet(System.nanoTime() - t0);
      return result;
   }