SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
The next generation MOP
Jochen "blackdrag" Theodorou
About blackdrag
● Working on Groovy Core since about 2005
● Almost as long as that, Tech Lead of Groovy
● Currently Employed at Pivotal
● Responsible for most of the technical side of
Groovy
Email: blackdrag@gmx.org
About a new MOP
● discussions since 2005
● good-for-all solution always missing
● some ideas open to discussion
● and some cleanup duties
● we insist on you helping us
Why change
Why change
● has many inconsistencies
● makes many optimizations impossible
● in theory powerful
● have to know implementation details
● Impossible to extend and spec resistent
● the API just plain sucks
Some Basics and History
The Meta Class
● Each class has a meta class
● Saves all the dynamic and static
properties/methods for Groovy
● Internal control flow involves exceptions
● Designed for invoking methods through
the meta class
The Meta Class
● early Groovy meta programming:
● MOP methods invokeMethod and get/setProperty
● A custom meta class (foo.metaClass = x)
● later class based automated meta class lookup
● transformed into the meta class creation handle
(used by ExpandoMetaClass#enableGlobally())
The Meta Class
● Basic principle: Each instance has a meta class
● More specified: Only every GroovyObject instance
(later we changed that with a global map)
● Global registry specifying
initial meta class on first use
The Meta Class
// myMetaClass some custom metaclass
// meta class in registry different
def x1 = new X()
assert x1.metaClass != myMetaClass
x1.metaClass = myMetaClass
assert x1.metaClass == myMetaClass
def x2 = new X()
assert x2.metaClass != x1.metaClass
X.metaClass = myMetaClass
def phantom = new X()
def x3 = new X()
assert x3.metaClass == x1.metaClass
assert x3.metaClass != x2.metaClass
The Meta Class
X.metaClass = x2.metaClass
assert phantom.metaClass == ???
Adding Methods/Properties
● Standard meta class: MetaClassImpl
● does not support modifications
● New meta class for this: ExpandoMetaClass
● enabled with ExpandoMetaClass.enableGlobally()
● not always equally behaving to MetaClassImpl
More MetaClasses
● ProxyMetaClass (intercepting, decorating)
● MixinMetaClass (mixins)
● ClosureMetaClass (GeneratedClosure)
● DelegatingMetaClass (base class)
● OwnedMetaClass (related to mixins)
● HandleMetaClass (related to mixins)
Plus your own custom meta class
DSL not consistent
Foo.metaClass.bar = 1 //defines property
Foo.metaClass.bar = {1} //defines method
to use a closure as property:
foo.metaClass.bar = null
foo.bar = {1}
● only for the instance
● get metaproperty and set initial value creator
Overriding Super Methods
class A {
def doIt(){two() + ' done.'}
def two(){'two'}
}
class B extends A {}
B.metaClass.two = {'my new two!'}
def b = new B()
assert b.two() == 'my new two!'
assert b.doIt() == 'two done.'
Overriding Super Methods
To make it work:
class A implements GroovyInterceptable {
def doIt(){two() + ' done.'}
def two(){'two'}
}
class B extends A {}
B.metaClass.two = {'my new two!'}
def b = new B()
assert b.two() == 'my new two!'
assert b.doIt() == 'my new two! done.'
Adding Super Methods
class A {
def doIt(){two() + ' done.'}
def methodMissing(String name, args){'two'}
}
class B extends A {}
def b = new B()
assert b.two() == 'two'
assert b.doIt() == 'two done.'
A.metaClass.two = {'my new two!'}
assert b.two() == 'my new two!'
assert b.doIt() == 'my new two! done.'
Super Methods Overload
Does not:
class A {
def doIt(x){two(x) + ' done.'}
def two(x) {'two'}
}
class B extends A {}
def b = new B()
assert b.two('1') == 'two'
assert b.doIt('1') == 'two done.'
A.metaClass.two = {String s->'my new two!'}
assert b.two('1') == 'my new two!'
assert b.doIt('1') == 'my new two! done.'
Private Multi Methods
class A {
def doIt(){two() + ' done.'}
}
class B extends A {
private two(){1}
}
def b = new B()
assert b.two() == 1
assert b.doIt() == '1 done.'
Speaking of private
class A {
private foo=1
def b={foo}
}
class B extends A {}
def b = new B()
assert b.b() == 1 //fails
● Information loss thorugh Closure#getProperty
get/setMetaClass
● persistency framework needs to be aware
● transient works for Serialization
● what about other frameworks?
● seamless integration anyone?
Properties
class X extends
org.xml.sax.helpers.XMLFilterImpl {
def foo
}
● XMLFilterImpl has a get/setProperty
● cannot do new X().foo = bar
● cannot do println new X().foo
invokeMethod
No such conflict known.... but!
● dynamic entry point from Java
● as methodMissing
● with GroovyInterceptable (EMC too) as upfront
method
conflicting concepts
What to make better?
… besides fixing those problems
Optimization efforts
Lesson:
Java7 with invokedynamic is much better suited for
Groovy's dynamic method calls
Reaction:
make Java7 the default (backport); rewrite
DefaultGroovyMethods to use indy; throw out a lot of
old code
Optimization efforts
Lesson:
Hotspot is not happy about invoking target methods in
the meta class (mega morphic call sites)
Reaction:
The meta class only gives back something you can call
and does not do the call itself.
Optimization efforts
Lesson:
Synchronization, Locks, volatiles usages on each
method call destroy multithread performance as well
as hotspot optimizations. Most applications set up mc
changes on startup.
Reaction:
metaclass goes immutable; adding methods creates
new meta class; lazy thread update (user level
synchronization required)
Hot Swapping
Lesson:
Keeping internal state in the class is bad (see
timestamp_xxx, timestamp, $callSiteArray)
Reaction:
Removal. CallSiteArray not needed anymore, the
timestamps are kept track off by the loader, not in the
class
Optimization efforts
Lesson:
Garbage collecting and recreating meta classes is very
bad.
Reaction:
Keep the base meta class around and reuse everything
possible to make new meta classes as lean as possible
API Design
Lesson:
Conventions are good, forcing them is bad
(GroovyObject)
Reaction:
Don't implement GroovyObject by default anymore.
General Design
Lesson:
Too many ways of doing the same thing is no good
Reaction:
Most probably only methodMissing/propertyMissing
anymore but easy way to „register“ a method to do
invokeMethod.
API Design
Lesson:
Having multiple, not equivalent entry points is bad.
(MetaClassImpl has 3 for methods, multiusage of
invokeMethod, information loss through
get/setProperty)
Reaction:
Clean up the API to have only one entry point
(removal of MetaClass#invokeMethod)
Possibilities
Internal vs. External
Internal usage:
class X {
def methodMissing(String name, args) {1}
}
External usage:
class X {}
X.metaClass.methodMissing = {1}
Combined:
class X {
static {this.metaClass.methodMissing = {1}}
}
Dynamic Invoke from Java
Before:
GroovyObject foo = ...;
String s = (String)
foo.invokeMethod(“bar“, new Object[]{});
After:
Object foo = ...;
String s = MopInterface.invoke(foo, “bar“);
● helper class for dynamic interactions with Groovy
● similiar for properties
Adding a method from Java
Before:
GroovyObject foo = ...;
foo.getMetaClass().registerInstanceMethod(“foo“,
new Closure(null){
public Object doCall(){1}};
After:
Object foo = ...;
MopInterface.addInstanceMethod(foo, “foo“,
new T() {
public Object myFancyMethod(){1}});
● Doesn't have to be a Closure or MetaMethod
● All declared methods used (lambdas too)
Limited Meta Class Changes
Use Case:
unrolling all changes a GroovyShell or Eval.me did
Before:
● tracking meta class mutations impossible
● „unmutate“ the metaclass certainly is
● can only to track newly set meta classes
Limited Meta Class Changes
Use Case:
I am a library developer and I don't want intrusive
changes from user code to my library classes,
changing the way my library is calling methods.
Before:
If the change is not effecting the library, then most
probably because of a bug.
Realms
Realms
A realm here defines how the class in the realm
„sees“ the meta classes. Different classes can have
different realms.
MyClass
(y)
MyOtherClass
(x)
x.foo()
using metaClass(x)
Realms
MyClass
(y)
MyOtherClass
(x)
x.foo()
using metaClass(x)
from realm(MyClass)
<Realm defined by MyClass>
Realms
MyClass
(y)
MyOtherClass
(x)
y.bar()
using metaClass(y)
from realm(MyOtherClass)
<Realm defined by MyOtherClass>
Realms
INIT
DEFAULT
realm(A_n)
realm(C_n)realm(A_1)
........
realm(B_1)
realm(C_1)
........
realm(D_1)
Realms
INIT does not allow changing the meta class
INIT
DEFAULT
Non isolated
isolated
Realms
Default gets all the unspecified changes
INIT
DEFAULT
Non isolated
isolated
Realms
Isolated realms don't get unspecific changes
INIT
DEFAULT
Non isolated
isolated
Realms
Non isolated realms can override meta classes in
default without impossing them
INIT
DEFAULT
Non isolated
isolated
Isolated Realm
@Realm(
marker=SomeMarkerClass,
parentRealm=Realm.INIT)
class MyLibraryClass {
def foo(){bar()}
def bar(){1}
}
MyLibraryClass.metaClass.bar = {2}
assert new MyLibraryClass().foo() == 1
Non-Isolated Realm
@Realm(marker=SomeMarkerClass)
class MyLibraryClass {
def foo(){bar()}
def bar(){1}
}
MyLibraryClass.metaClass.bar = {2}
assert new MyLibraryClass().foo() == 2
Testing Realm
class X {private foo(){1}}
class MyTest extends GroovyTestCase {
@Realm(marker=SomeMarkerClass,
allowPrivate=true)
void testPrivateWorking() {
def x = new X()
assert x.foo() == 1
}
void testPrivateNotWorking() {
def x = new X()
shouldFail(MissingMethodException) {
x.foo()
}
}
}
Limited Meta Class Changes
Before:
Change intrusive, visible to everyone
After:
def foo(){1}
assert foo() == 1
realm.withSubRealm {
this.metaClass.foo = {2}
assert foo() == 2
}
assert foo() == 1
Q/A?

Weitere ähnliche Inhalte

Was ist angesagt?

Hotspot & hotswap, who and who are best freinds
Hotspot & hotswap, who and who are best freindsHotspot & hotswap, who and who are best freinds
Hotspot & hotswap, who and who are best freinds亚军 汪
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHPLorna Mitchell
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topicsRajesh Verma
 
Running Pharo on the GemStone VM
Running Pharo on the GemStone VMRunning Pharo on the GemStone VM
Running Pharo on the GemStone VMESUG
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceOUM SAOKOSAL
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Framework prototype
Framework prototypeFramework prototype
Framework prototypeDevMix
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 

Was ist angesagt? (18)

Hotspot & hotswap, who and who are best freinds
Hotspot & hotswap, who and who are best freindsHotspot & hotswap, who and who are best freinds
Hotspot & hotswap, who and who are best freinds
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 
Shiksharth com java_topics
Shiksharth com java_topicsShiksharth com java_topics
Shiksharth com java_topics
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Running Pharo on the GemStone VM
Running Pharo on the GemStone VMRunning Pharo on the GemStone VM
Running Pharo on the GemStone VM
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Java Reflection
Java ReflectionJava Reflection
Java Reflection
 
Java basic
Java basicJava basic
Java basic
 
Unit3 part2-inheritance
Unit3 part2-inheritanceUnit3 part2-inheritance
Unit3 part2-inheritance
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Java chapter 4
Java chapter 4Java chapter 4
Java chapter 4
 
Introduction to OOP(in java) BY Govind Singh
Introduction to OOP(in java)  BY Govind SinghIntroduction to OOP(in java)  BY Govind Singh
Introduction to OOP(in java) BY Govind Singh
 
Framework prototype
Framework prototypeFramework prototype
Framework prototype
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 

Ähnlich wie The Next Generation MOP, Jochen Theodorou, GR8Conf 2013

Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsMarcin Grzejszczak
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013rivierarb
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.pptParikhitGhosh1
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Nayden Gochev
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders? guestd56374
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerIgor Crvenov
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming RailsJustus Eapen
 

Ähnlich wie The Next Generation MOP, Jochen Theodorou, GR8Conf 2013 (20)

Introduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transformsIntroduction to Groovy runtime metaprogramming and AST transforms
Introduction to Groovy runtime metaprogramming and AST transforms
 
Only oop
Only oopOnly oop
Only oop
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
 
Intro to Rails 4
Intro to Rails 4Intro to Rails 4
Intro to Rails 4
 
Code Refactoring
Code RefactoringCode Refactoring
Code Refactoring
 
Refactoring Chapter11
Refactoring Chapter11Refactoring Chapter11
Refactoring Chapter11
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
Lecture from javaday.bg by Nayden Gochev/ Ivan Ivanov and Mitia Alexandrov
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Do you really get class loaders?
Do you really get class loaders? Do you really get class loaders?
Do you really get class loaders?
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
Refactoring Tips by Martin Fowler
Refactoring Tips by Martin FowlerRefactoring Tips by Martin Fowler
Refactoring Tips by Martin Fowler
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Inheritance
InheritanceInheritance
Inheritance
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 

Mehr von GR8Conf

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle GR8Conf
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerGR8Conf
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with GroovyGR8Conf
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with GebGR8Conf
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidGR8Conf
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the DocksGR8Conf
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsGR8Conf
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applicationsGR8Conf
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3GR8Conf
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGR8Conf
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEBGR8Conf
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCGR8Conf
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshopGR8Conf
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spockGR8Conf
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedGR8Conf
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGR8Conf
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and GroovyGR8Conf
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineGR8Conf
 

Mehr von GR8Conf (20)

DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle Creating and testing REST contracts with Accurest Gradle
Creating and testing REST contracts with Accurest Gradle
 
Mum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developerMum, I want to be a Groovy full-stack developer
Mum, I want to be a Groovy full-stack developer
 
Metaprogramming with Groovy
Metaprogramming with GroovyMetaprogramming with Groovy
Metaprogramming with Groovy
 
Scraping with Geb
Scraping with GebScraping with Geb
Scraping with Geb
 
How to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and AndroidHow to create a conference android app with Groovy and Android
How to create a conference android app with Groovy and Android
 
Ratpack On the Docks
Ratpack On the DocksRatpack On the Docks
Ratpack On the Docks
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Cut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature pluginsCut your Grails application to pieces - build feature plugins
Cut your Grails application to pieces - build feature plugins
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
Ratpack and Grails 3
 Ratpack and Grails 3 Ratpack and Grails 3
Ratpack and Grails 3
 
Grails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloudGrails & DevOps: continuous integration and delivery in the cloud
Grails & DevOps: continuous integration and delivery in the cloud
 
Functional testing your Grails app with GEB
Functional testing your Grails app with GEBFunctional testing your Grails app with GEB
Functional testing your Grails app with GEB
 
Deploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPCDeploying, Scaling, and Running Grails on AWS and VPC
Deploying, Scaling, and Running Grails on AWS and VPC
 
The Grails introduction workshop
The Grails introduction workshopThe Grails introduction workshop
The Grails introduction workshop
 
Idiomatic spock
Idiomatic spockIdiomatic spock
Idiomatic spock
 
The Groovy Ecosystem Revisited
The Groovy Ecosystem RevisitedThe Groovy Ecosystem Revisited
The Groovy Ecosystem Revisited
 
Groovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examplesGroovy 3 and the new Groovy Meta Object Protocol in examples
Groovy 3 and the new Groovy Meta Object Protocol in examples
 
Integration using Apache Camel and Groovy
Integration using Apache Camel and GroovyIntegration using Apache Camel and Groovy
Integration using Apache Camel and Groovy
 
CRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual MachineCRaSH the shell for the Java Virtual Machine
CRaSH the shell for the Java Virtual Machine
 

Kürzlich hochgeladen

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Kürzlich hochgeladen (20)

2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

The Next Generation MOP, Jochen Theodorou, GR8Conf 2013

  • 1. The next generation MOP Jochen "blackdrag" Theodorou
  • 2. About blackdrag ● Working on Groovy Core since about 2005 ● Almost as long as that, Tech Lead of Groovy ● Currently Employed at Pivotal ● Responsible for most of the technical side of Groovy Email: blackdrag@gmx.org
  • 3. About a new MOP ● discussions since 2005 ● good-for-all solution always missing ● some ideas open to discussion ● and some cleanup duties ● we insist on you helping us
  • 5. Why change ● has many inconsistencies ● makes many optimizations impossible ● in theory powerful ● have to know implementation details ● Impossible to extend and spec resistent ● the API just plain sucks
  • 6. Some Basics and History
  • 7. The Meta Class ● Each class has a meta class ● Saves all the dynamic and static properties/methods for Groovy ● Internal control flow involves exceptions ● Designed for invoking methods through the meta class
  • 8. The Meta Class ● early Groovy meta programming: ● MOP methods invokeMethod and get/setProperty ● A custom meta class (foo.metaClass = x) ● later class based automated meta class lookup ● transformed into the meta class creation handle (used by ExpandoMetaClass#enableGlobally())
  • 9. The Meta Class ● Basic principle: Each instance has a meta class ● More specified: Only every GroovyObject instance (later we changed that with a global map) ● Global registry specifying initial meta class on first use
  • 10. The Meta Class // myMetaClass some custom metaclass // meta class in registry different def x1 = new X() assert x1.metaClass != myMetaClass x1.metaClass = myMetaClass assert x1.metaClass == myMetaClass def x2 = new X() assert x2.metaClass != x1.metaClass X.metaClass = myMetaClass def phantom = new X() def x3 = new X() assert x3.metaClass == x1.metaClass assert x3.metaClass != x2.metaClass
  • 11. The Meta Class X.metaClass = x2.metaClass assert phantom.metaClass == ???
  • 12. Adding Methods/Properties ● Standard meta class: MetaClassImpl ● does not support modifications ● New meta class for this: ExpandoMetaClass ● enabled with ExpandoMetaClass.enableGlobally() ● not always equally behaving to MetaClassImpl
  • 13. More MetaClasses ● ProxyMetaClass (intercepting, decorating) ● MixinMetaClass (mixins) ● ClosureMetaClass (GeneratedClosure) ● DelegatingMetaClass (base class) ● OwnedMetaClass (related to mixins) ● HandleMetaClass (related to mixins) Plus your own custom meta class
  • 14. DSL not consistent Foo.metaClass.bar = 1 //defines property Foo.metaClass.bar = {1} //defines method to use a closure as property: foo.metaClass.bar = null foo.bar = {1} ● only for the instance ● get metaproperty and set initial value creator
  • 15. Overriding Super Methods class A { def doIt(){two() + ' done.'} def two(){'two'} } class B extends A {} B.metaClass.two = {'my new two!'} def b = new B() assert b.two() == 'my new two!' assert b.doIt() == 'two done.'
  • 16. Overriding Super Methods To make it work: class A implements GroovyInterceptable { def doIt(){two() + ' done.'} def two(){'two'} } class B extends A {} B.metaClass.two = {'my new two!'} def b = new B() assert b.two() == 'my new two!' assert b.doIt() == 'my new two! done.'
  • 17. Adding Super Methods class A { def doIt(){two() + ' done.'} def methodMissing(String name, args){'two'} } class B extends A {} def b = new B() assert b.two() == 'two' assert b.doIt() == 'two done.' A.metaClass.two = {'my new two!'} assert b.two() == 'my new two!' assert b.doIt() == 'my new two! done.'
  • 18. Super Methods Overload Does not: class A { def doIt(x){two(x) + ' done.'} def two(x) {'two'} } class B extends A {} def b = new B() assert b.two('1') == 'two' assert b.doIt('1') == 'two done.' A.metaClass.two = {String s->'my new two!'} assert b.two('1') == 'my new two!' assert b.doIt('1') == 'my new two! done.'
  • 19. Private Multi Methods class A { def doIt(){two() + ' done.'} } class B extends A { private two(){1} } def b = new B() assert b.two() == 1 assert b.doIt() == '1 done.'
  • 20. Speaking of private class A { private foo=1 def b={foo} } class B extends A {} def b = new B() assert b.b() == 1 //fails ● Information loss thorugh Closure#getProperty
  • 21. get/setMetaClass ● persistency framework needs to be aware ● transient works for Serialization ● what about other frameworks? ● seamless integration anyone?
  • 22. Properties class X extends org.xml.sax.helpers.XMLFilterImpl { def foo } ● XMLFilterImpl has a get/setProperty ● cannot do new X().foo = bar ● cannot do println new X().foo
  • 23. invokeMethod No such conflict known.... but! ● dynamic entry point from Java ● as methodMissing ● with GroovyInterceptable (EMC too) as upfront method conflicting concepts
  • 24. What to make better?
  • 25. … besides fixing those problems
  • 26. Optimization efforts Lesson: Java7 with invokedynamic is much better suited for Groovy's dynamic method calls Reaction: make Java7 the default (backport); rewrite DefaultGroovyMethods to use indy; throw out a lot of old code
  • 27. Optimization efforts Lesson: Hotspot is not happy about invoking target methods in the meta class (mega morphic call sites) Reaction: The meta class only gives back something you can call and does not do the call itself.
  • 28. Optimization efforts Lesson: Synchronization, Locks, volatiles usages on each method call destroy multithread performance as well as hotspot optimizations. Most applications set up mc changes on startup. Reaction: metaclass goes immutable; adding methods creates new meta class; lazy thread update (user level synchronization required)
  • 29. Hot Swapping Lesson: Keeping internal state in the class is bad (see timestamp_xxx, timestamp, $callSiteArray) Reaction: Removal. CallSiteArray not needed anymore, the timestamps are kept track off by the loader, not in the class
  • 30. Optimization efforts Lesson: Garbage collecting and recreating meta classes is very bad. Reaction: Keep the base meta class around and reuse everything possible to make new meta classes as lean as possible
  • 31. API Design Lesson: Conventions are good, forcing them is bad (GroovyObject) Reaction: Don't implement GroovyObject by default anymore.
  • 32. General Design Lesson: Too many ways of doing the same thing is no good Reaction: Most probably only methodMissing/propertyMissing anymore but easy way to „register“ a method to do invokeMethod.
  • 33. API Design Lesson: Having multiple, not equivalent entry points is bad. (MetaClassImpl has 3 for methods, multiusage of invokeMethod, information loss through get/setProperty) Reaction: Clean up the API to have only one entry point (removal of MetaClass#invokeMethod)
  • 35. Internal vs. External Internal usage: class X { def methodMissing(String name, args) {1} } External usage: class X {} X.metaClass.methodMissing = {1} Combined: class X { static {this.metaClass.methodMissing = {1}} }
  • 36. Dynamic Invoke from Java Before: GroovyObject foo = ...; String s = (String) foo.invokeMethod(“bar“, new Object[]{}); After: Object foo = ...; String s = MopInterface.invoke(foo, “bar“); ● helper class for dynamic interactions with Groovy ● similiar for properties
  • 37. Adding a method from Java Before: GroovyObject foo = ...; foo.getMetaClass().registerInstanceMethod(“foo“, new Closure(null){ public Object doCall(){1}}; After: Object foo = ...; MopInterface.addInstanceMethod(foo, “foo“, new T() { public Object myFancyMethod(){1}}); ● Doesn't have to be a Closure or MetaMethod ● All declared methods used (lambdas too)
  • 38. Limited Meta Class Changes Use Case: unrolling all changes a GroovyShell or Eval.me did Before: ● tracking meta class mutations impossible ● „unmutate“ the metaclass certainly is ● can only to track newly set meta classes
  • 39. Limited Meta Class Changes Use Case: I am a library developer and I don't want intrusive changes from user code to my library classes, changing the way my library is calling methods. Before: If the change is not effecting the library, then most probably because of a bug.
  • 41. Realms A realm here defines how the class in the realm „sees“ the meta classes. Different classes can have different realms. MyClass (y) MyOtherClass (x) x.foo() using metaClass(x)
  • 45. Realms INIT does not allow changing the meta class INIT DEFAULT Non isolated isolated
  • 46. Realms Default gets all the unspecified changes INIT DEFAULT Non isolated isolated
  • 47. Realms Isolated realms don't get unspecific changes INIT DEFAULT Non isolated isolated
  • 48. Realms Non isolated realms can override meta classes in default without impossing them INIT DEFAULT Non isolated isolated
  • 49. Isolated Realm @Realm( marker=SomeMarkerClass, parentRealm=Realm.INIT) class MyLibraryClass { def foo(){bar()} def bar(){1} } MyLibraryClass.metaClass.bar = {2} assert new MyLibraryClass().foo() == 1
  • 50. Non-Isolated Realm @Realm(marker=SomeMarkerClass) class MyLibraryClass { def foo(){bar()} def bar(){1} } MyLibraryClass.metaClass.bar = {2} assert new MyLibraryClass().foo() == 2
  • 51. Testing Realm class X {private foo(){1}} class MyTest extends GroovyTestCase { @Realm(marker=SomeMarkerClass, allowPrivate=true) void testPrivateWorking() { def x = new X() assert x.foo() == 1 } void testPrivateNotWorking() { def x = new X() shouldFail(MissingMethodException) { x.foo() } } }
  • 52. Limited Meta Class Changes Before: Change intrusive, visible to everyone After: def foo(){1} assert foo() == 1 realm.withSubRealm { this.metaClass.foo = {2} assert foo() == 2 } assert foo() == 1
  • 53. Q/A?